0

Assuming a user initiates a Jenkins job, passing some input parameters.

Is there a way, at some point to have the Jenkins job trigger a gitlab-ci, and also pass to it (i.e. the gitlab pipeline) some input parameters which the latter will use as environment variables?

3
  • 1
    That sounds uterly strange to chain two CI systems... what's the point ?
    – Tensibai
    Feb 7, 2018 at 8:41
  • Cannot find a way to provide user input for manual pipeline triggering in gitlab (where a lot of my infrastructure lies right now).
    – pkaramol
    Feb 7, 2018 at 8:42
  • 1
    That sounds an XY problem (as adding jenkins is already a try to solution the real problem) but I assume this could help: docs.gitlab.com/ee/api/jobs.html
    – Tensibai
    Feb 7, 2018 at 9:31

1 Answer 1

2

Note: I didn't use this yet, the answer is based solely on documentation.

A GitlabCI pipeline can be triggered via API, see Triggering pipelines through the API.

Triggers can be used to force a pipeline rerun of a specific ref (branch or tag) with an API call.

You would first need to create a trigger for that pipeline.

Then you can activate that trigger (from your jenkins job in this case):

To trigger a job you need to send a POST request to GitLab's API endpoint:

POST /projects/:id/trigger/pipeline

The required parameters are the trigger's token and the Git ref on which the trigger will be performed. Valid refs are the branch and the tag.

Such triggers support variable passing:

You can pass any number of arbitrary variables in the trigger API call and they will be available in GitLab CI so that they can be used in your .gitlab-ci.yml file. The parameter is of the form:

variables[key]=value

You can use the variables inside .gitlab-ci.yml like this:

upload_package:
  stage: package
  script:
  - if [ -n "${UPLOAD_TO_S3}" ]; then make upload; fi

And

You can then trigger a rebuild while you pass the UPLOAD_TO_S3 variable and the script of the upload_package job will run:

curl --request POST \
  --form token=TOKEN \
  --form ref=master \
  --form "variables[UPLOAD_TO_S3]=true" \
  https://gitlab.example.com/api/v4/projects/9/trigger/pipeline

This kind of POST requests is what you would to do in your jenkins job. But take a closer look at the triggers, you might find a way to do what you want without jenkins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.