I have a GitLag repo with a define pipeline. I want to trigger that pipeline 10 times…
- User
I have a GitLag repo with a define pipeline.
I want to trigger that pipeline 10 times with different values for the environment variables and sequentially. How can I do it?
- Assistant
You can use GitLab's API to trigger the pipeline and pass in different environment variables for each trigger. Here's an example of how you might do this using the
curlcommand:bash - User
Ok, the only variable I need is CLUSTER_ID and its value is from cluster01 to cluster10.
Could you adapt the previous code to these 10 pipelines?
- Assistant
Sure, here's an example of how you might trigger 10 pipelines with different values for the
CLUSTER_IDenvironment variable:bash# Define token, project ID, and base URL TOKEN=[YOUR_TOKEN] PROJECT_ID=[PROJECT_ID] URL=https://gitlab.com/api/v4/projects/$PROJECT_ID/trigger/pipeline # Loop through 10 different values for CLUSTER_ID for i in {1..10}; do # Trigger pipeline with current value of CLUSTER_ID curl --request POST --form token=$TOKEN --form ref=master $URL -F "variables[CLUSTER_ID]=cluster0$i" # Wait for pipeline to finish while true; do status=$(curl --silent --request GET --header "PRIVATE-TOKEN: $TOKEN" "$URL/$pipeline_id" | jq '.status') if [ "$status" = "\"success\"" ]; then break fi done doneYou will need to replace the placeholders
[YOUR_TOKEN]and[PROJECT_ID]with your own values. - User
Ok, so include the extraction and use of the pipeline_id in the script, please.
- Assistant
Sure, here is an example of how you might trigger 10 pipelines with different values for the
CLUSTER_IDenvironment variable, and keeping track of the pipeline_id:bash