Need to pass env variable from python script to gitlab ci pipeline. Tried
responce = requests.post("https://gitlab.com/api/v4/projects/{project_id}/trigger/pipeline", data={'token': 'token', 'ref': 'branch', 'variables': [{'key': 'MR_ID', 'value': 'VALUE'}])
responce = requests.post("https://gitlab.com/api/v4/projects/{project_id}/trigger/pipeline", data={'token': 'token', 'ref': 'branch', {variables': [{'key': 'MR_ID', 'value': 'VALUE'}]})
Getting {"error":"variables is invalid"} all the time.
Here is what documentation says: https://docs.gitlab.com/ee/api/pipelines.html#create-a-new-pipeline
Could anybody provide real working python example?
Looks like you misunderstand what the data
parameter is in a requests.post
. If you have a look at the docs you can see, that the information from data
will be delivered in the body.
What you want to fulfill the gitlab API is the params
parameter of requests.
params
will encode the data
in the URL as query parameter like this:
requests.post("https://gitlab.example.com/api/v4/projects/YOUR_PROJECT_ID/pipeline", params={"MR_ID": "VALUE"});
So you have to put your variables
in the params
parameter and the other information you have in data
at the right place (like token in the header etc.)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments