Operations 3 min read

Triggering GitLab CI Pipelines via API and Passing Parameters

This article demonstrates how to set up a GitLab CI pipeline trigger token, use curl or Postman to invoke the pipeline via API, embed the trigger in .gitlab-ci.yml, and pass custom variables to the job, with example scripts and best‑practice tips.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Triggering GitLab CI Pipelines via API and Passing Parameters

The preparation steps include configuring the project, CI/CD settings, and creating a dedicated authentication token for pipeline triggers.

To trigger a pipeline via API, you can use a curl command such as:

curl -X POST \
      -F token=b2ba95b229f5fd0eb834454bc9aad8 \
      -F ref=main \
      http://192.168.1.200/api/v4/projects/31/trigger/pipeline

Postman can also be used for testing the same endpoint.

Within a GitLab CI job, the trigger can be invoked directly:

script:
  - "curl -X POST -F token=TOKEN -F ref=REF_NAME http://192.168.1.200/api/v4/projects/31/trigger/pipeline"

For better security, store the token as a CI/CD variable and reference it in the script:

stages:
  - build

build-job:
  tags:
    - build
  stage: build
  script:
    - "curl -X POST -F token=${CITOKEN} -F ref=main  http://192.168.1.200/api/v4/projects/29/trigger/pipeline"
    - echo "Compile complete."
    - sleep 1

Parameters can be passed to the pipeline by adding them as variables in the API call:

curl -X POST \
      -F token=TOKEN \
      -F "ref=main" \
      -F "variables[BUILD_TOOL]=mavenandmaven" \
      http://192.168.1.200/api/v4/projects/31/trigger/pipeline

A corresponding job can retrieve and use the variable:

ciTriggerTest:
  tags:
    - build
  stage: build
  script:
    - echo ${BUILD_TOOL}

The article concludes with a note that the content is excerpted from the third DevOps practice training camp and invites readers to follow the DevOps Cloud Academy for more resources.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdDevOpsGitLab CIcURLPipelineAPI trigger
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.