Answers: <p>Note: I didn't use this yet, the answer is based solely on documentation.</p>
  
  <p>A GitlabCI pipeline can be triggered via API, see <a href="https://docs.gitlab.com/ee/ci/triggers/" rel="nofollow noreferrer">Triggering pipelines through the API</a>. </p>
  
  <blockquote>
    <p>Triggers can be used to force a pipeline rerun of a specific <code>ref</code> (branch or tag) with an API call.</p>
  </blockquote>
  
  <p>You would first need to <a href="https://docs.gitlab.com/ee/ci/triggers/#adding-a-new-trigger" rel="nofollow noreferrer">create a trigger</a> for that pipeline.</p>
  
  <p>Then you can <a href="https://docs.gitlab.com/ee/ci/triggers/#triggering-a-pipeline" rel="nofollow noreferrer">activate that trigger</a> (from your jenkins job in this case):</p>
  
  <blockquote>
    <p>To trigger a job you need to send a <code>POST</code> request to GitLab's API
    endpoint:</p>
  
  <pre><code>POST /projects/:id/trigger/pipeline
  </code></pre>
    
    <p>The required parameters are the <a href="https://docs.gitlab.com/ee/ci/triggers/#authentication-tokens" rel="nofollow noreferrer">trigger's <code>token</code></a> and the Git
    <code>ref</code> on which the trigger will be performed. Valid refs are the
    branch and the tag.</p>
  </blockquote>
  
  <p>Such triggers support <a href="https://docs.gitlab.com/ee/ci/triggers/#making-use-of-trigger-variables" rel="nofollow noreferrer">variable passing</a>:</p>
  
  <blockquote>
    <p>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 <code>.gitlab-ci.yml</code> file. The parameter is of the form:</p>
  
  <pre><code>variables[key]=value
  </code></pre>
  </blockquote>
  
  <p>You can use the variables inside <code>.gitlab-ci.yml</code> like this:</p>
  
  <blockquote>
  <pre><code>upload_package:
    stage: package
    script:
    - if [ -n "${UPLOAD_TO_S3}" ]; then make upload; fi
  </code></pre>
  </blockquote>
  
  <p>And</p>
  
  <blockquote>
    <p>You can then trigger a rebuild while you pass the <code>UPLOAD_TO_S3</code>
    variable and the script of the <code>upload_package</code> job will run:</p>
  
  <pre><code>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
  </code></pre>
  </blockquote>
  
  <p>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.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-02-07T18:01:27.193Z
Answers: 2018-02-07T18:01:27.193Z
Answers: Dan Cornilescu
Body: <p>Assuming a user initiates a Jenkins job, passing some input parameters.</p>
  
  <p>Is there a way, at some point to have the Jenkins job trigger a <code>gitlab-ci</code>, <strong>and</strong> also pass to it (i.e. the <code>gitlab</code> pipeline) some input parameters which the latter will use as environment variables?</p>
  
Comments: CC BY-SA 3.0
Comments: 2018-02-07T08:41:12.907Z
Comments: That sounds uterly strange to chain two CI systems... what's the point ?
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2018-02-07T08:42:04.310Z
Comments: Cannot find a way to provide user input for manual pipeline triggering in gitlab (where a lot of my infrastructure lies right now).
Comments: pkaramol
Comments: CC BY-SA 3.0
Comments: 2018-02-07T09:31:04.747Z
Comments: That sounds an XY problem (as adding jenkins is already a try to solution the real problem) but I assume this could help: https://docs.gitlab.com/ee/api/jobs.html
Comments: Tensibai
Tags: <jenkins><continuous-integration><continuous-deployment><gitlab><gitlab-ci-runner>
Title: Have Jenkins trigger GitlabCI
UserDisplayName: pkaramol
ThreadText: # Have Jenkins trigger GitlabCI
  
  (Asked by: username_0 on 2018-02-07)
  
  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?
  
  **Tags:** jenkins, continuous-integration, continuous-deployment, gitlab, gitlab-ci-runner
  
  > **Comments:**
  > **username_1**: That sounds uterly strange to chain two CI systems... what's the point ?  
  > **username_0**: Cannot find a way to provide user input for manual pipeline triggering in gitlab (where a lot of my infrastructure lies right now).  
  > **username_1**: That sounds an XY problem (as adding jenkins is already a try to solution the real problem) but I assume this could help: https://docs.gitlab.com/ee/api/jobs.html  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-02-07. Score: 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](https://docs.gitlab.com/ee/ci/triggers/).
  
  > 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](https://docs.gitlab.com/ee/ci/triggers/#adding-a-new-trigger) for that pipeline.
  
  Then you can [activate that trigger](https://docs.gitlab.com/ee/ci/triggers/#triggering-a-pipeline) (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`](https://docs.gitlab.com/ee/ci/triggers/#authentication-tokens) and the Git
  > `ref` on which the trigger will be performed. Valid refs are the
  > branch and the tag.
  
  Such triggers support [variable passing](https://docs.gitlab.com/ee/ci/triggers/#making-use-of-trigger-variables):
  
  > 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.
  
  
  ---
  
  