Set pipeline name when triggering with api

Set pipeline name when triggering with api

We trigger a pipeline using the the API from the command line. This works fine, but the pipeline then shows up with the message of the last commit as title.

This commit message has no relevance to the run at all. How can we provide a name to be displayed in the Pipeline column on the Build - Pipelines page in Gitlab ?

@markus_ba Welcome to the forum!

I think the workflow:name keyword should help here. It can be combined with workflow:rules and $CI_PIPELINE_SOURCE to match on pipelines started through the API and given them a specific name.

I hope this helps!

-James H, GitLab Product Manager, Analyze:Product Analytics

Thanks, James,
this works perfectly well !

I just had to add

workflow:
   name: '$myRunName'`

to my .gitlab-ci.yml

and trigger with curl this way:

curl --form variables[myRunName]="this is my job name" ...

And I get my own title in the list.

Great ! Thanks !

Markus

1 Like

better runtime pipeline rename example


  after_script:
    - CUSTOM_PIPELINE_NAME="$CI_COMMIT_MESSAGE v:$Version"
    - CUSTOM_PIPELINE_NAME=$(echo "$CUSTOM_PIPELINE_NAME" | tr -d '\n')
    - apk update
    - apk add curl
    # or
    # -  apt-get update && apt-get install -qq -y curl > /dev/null
    - >
      curl
      -H "Job-Token: $CI_JOB_TOKEN"
      -X PUT
      --data "name=$CUSTOM_PIPELINE_NAME"
      $CI_API_V4_URL/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/metadata
1 Like

This! Thank you so much! You have just given me the solution I was hoping for. This is an excellent answer that can be used in any job at any stage. Elegant because it uses an after-script and therefor does not rename all the pipelines for all the stages in your CI/CD.