How to pass env variables from python script to gitlab ci with requests?

A. Makarevich

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?

BreakBB

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to pass all values from multiple Secrets to env variables in Kubernetes?

Get env variables from script and pass to Dockerfile

How to pass values to a Gitlab CI Job

How to use protected enviroment variables from gitlab CI/CD inside serverless script?

How to backup/export Gitlab CI environment variables?

How do I pass gitlab-ci variables to karate Netty jar?

Env vars lost when building docker image from Gitlab CI

Gitlab-ci and docker - env variables

Can I pass environment variables from Gitlab .gitlab-ci.yml to a React app?

Share env variables between Docker-Compose and GitLab-CI

How to pass variables from a Robot Test script to Python script

How to use ci.yml to declare env variables to be used in python?

How do I pass the Gitlab {CI_COMMIT_SHORT_SHA} variable to powershell script

How to pass variables from .gitlab.ci.yml to Dockerfile

gitlab-ci: exclude merge requests from specific branch

How to set environment variables in travis-ci and access them from python script?

GitLab CI Script variables

How to pass environment variables into .gitlab-ci.yml in Gitlab for Spring Boot?

Can a gitlab CI script be reused using branch specific variables?

How to pass pipeline credential parameter to python script as env variable

How to set the result of docker inspect to an env variable in gitlab-ci script

How to pass .env variables from docker-compose to entrypoint's script?

Using shell variables within a Gitlab CI/CD pipeline script?

Gitlab CI variables and script section give different results

Can I pass a variable from .env file into .gitlab-ci.yml

How to (implicitly) pass environment variables to Maven build in gitlab-ci.yml for a Spring Boot application?

Dynamically create gitlab-ci variables starting from a script

how to access specific key in Variables from file, gitlab-ci

How can I pass a variable from one job to another in GitLab CI if jobs are in the same stage?