<p>In your job, I noticed the below curl command, where two things need to be corrected:</p>

<ul>
<li><p><code>token=$CI_JOB_TOKEN</code> - this TOKEN should be generated in project B under Settings -> CI/CD -> Pipeline triggers (Add triggers)</p></li>
<li><p><code>"ref=$CI_COMMIT_REF_NAME"</code> - this is pointing to a branch with name $CI_COMMIT_REF_NAME on project B and this will only execute if it find a project with that branch name, so if you are trying to trigger it on master branch or any specific branch, you should replace it with something like <code>-F "ref=master"</code> in your curl command</p></li>
</ul>

<pre><code> - curl -X POST -F "token=$CI_JOB_TOKEN" -F "ref=$CI_COMMIT_REF_NAME" https://gitlab.com/api/v4/projects/1234/trigger/pipeline
</code></pre>

<p>I use the same trigger with few variables to execute one of my job in another project</p>

<pre><code>- "curl -k -X POST -F token=$PROJECT_B_TOKEN -F ref=master -F variables[PROJECT_NAME]=$CI_PROJECT_NAME -F variables[TAG]=$CI_BUILD_REF_NAME -F variables[SOME_VARIABLE_IDENTIFIER]=DevOps -F variables[USER]=$GITLAB_USER_LOGIN https://gitlab.mycompany.com/api/v4/projects/1234/trigger/pipeline"
</code></pre>

<p>The person who created in token in project B, needs to be owner in project A to execute this trigger, else it fails with a 404 message.</p>

CC BY-SA 4.0
2019-01-16T15:54:15.190Z
2019-01-16T15:54:15.190Z
rebelution
<p>I am trying to call a trigger on one GitLab project using a job on another. </p>

<p>Let’s call one A, and the other B. I want a job in A to trigger a job in B.</p>

<p>In A, this is what my <code>.gitlab-ci.yml</code> looks like:</p>

<pre><code>deploy:staging:
  image: alpine
  variables:
    GIT_STRATEGY: none
  script:
    - apk add --no-cache curl
    - curl -X POST -F "token=$CI_JOB_TOKEN" -F "ref=$CI_COMMIT_REF_NAME" https://gitlab.com/api/v4/projects/1234/trigger/pipeline
</code></pre>

<p>In B, this is what my <code>.gitlab-ci.yml</code> looks like:</p>

<pre><code>image: google/cloud-sdk

deploy:staging:
  only:
    - triggers
  script:
    - echo "$CI_ENVIRONMENT_SLUG"
</code></pre>

<p>However, when A runs, I get the following result from curl:</p>

<pre><code>{"message":{"base":["Reference not found"]}}
</code></pre>

<p>When I hardcode the ref to master, I get this message:</p>

<pre><code>{"message":{"base":["No stages / jobs for this pipeline."]}}
</code></pre>

<p>How can A be configured, so that the <code>deploy:staging</code> job in B is triggered on master?</p>

<p>Thinking ahead, I would like to add more deployment targets, so it should <strong>only</strong> trigger the <code>deploy:staging</code> job.</p>

CC BY-SA 4.0
2018-09-19T13:29:40.840Z
your CI_JOB_TOKEN is not able to start another project pipeline, you need to create a token in B and hardcode it in A (unless you have premium or above edition of gitlab with cross-project pipelines and in this case their support is far more indicated to help you troubleshoot this problem)
Tensibai
CC BY-SA 4.0
2018-09-19T13:38:44.200Z
I do have GitLab silver, so it should work. I think otherwise I wouldn’t be able to get the message `"No stages / jobs for this pipeline."` either.
Remco Haszing
CC BY-SA 4.0
2018-09-19T14:34:24.033Z
Then I really think you should ask gitlab's support (which you pay for btw), as only people with the same subscription can try to reproduce your problem. In case it may help, my triggers (with hardcoded values) doesn't have quote for the parameters, I.e: -F token=xxxx -F ref=master
Tensibai
CC BY-SA 4.0
2018-09-19T14:35:43.957Z
Just in case, are you talking about hosted gitlab or on premise gitlab instance ?
Tensibai
CC BY-SA 4.0
2018-09-19T14:37:03.180Z
I’m using the hosted GitLab.
Remco Haszing
CC BY-SA 4.0
2018-09-19T14:38:31.493Z
Then we can't even dig in the logs to understand why it fails, you should really open a case at gitlab.com as they are the only ones able to see where and why it fails in the requests
Tensibai
<gitlab>
Trigger a cross project GitLab trigger
Remco Haszing
# Trigger a cross project GitLab trigger

(Asked by: username_0 on 2018-09-19)

I am trying to call a trigger on one GitLab project using a job on another. 
Let’s call one A, and the other B. I want a job in A to trigger a job in B.
In A, this is what my .gitlab-ci.yml looks like:
deploy:staging:
  image: alpine
  variables:
    GIT_STRATEGY: none
  script:
    - apk add --no-cache curl
    - curl -X POST -F "token=$CI_JOB_TOKEN" -F "ref=$CI_COMMIT_REF_NAME" https://gitlab.com/api/v4/projects/1234/trigger/pipeline

In B, this is what my .gitlab-ci.yml looks like:
image: google/cloud-sdk

deploy:staging:
  only:
    - triggers
  script:
    - echo "$CI_ENVIRONMENT_SLUG"

However, when A runs, I get the following result from curl:
{"message":{"base":["Reference not found"]}}

When I hardcode the ref to master, I get this message:
{"message":{"base":["No stages / jobs for this pipeline."]}}

How can A be configured, so that the deploy:staging job in B is triggered on master?
Thinking ahead, I would like to add more deployment targets, so it should only trigger the deploy:staging job.

**Tags:** gitlab

> **Comments:**
> **username_1**: your CI_JOB_TOKEN is not able to start another project pipeline, you need to create a token in B and hardcode it in A (unless you have premium or above edition of gitlab with cross-project pipelines and in this case their support is far more indicated to help you troubleshoot this problem)  
> **username_0**: I do have GitLab silver, so it should work. I think otherwise I wouldn’t be able to get the message `"No stages / jobs for this pipeline."` either.  
> **username_1**: Then I really think you should ask gitlab's support (which you pay for btw), as only people with the same subscription can try to reproduce your problem. In case it may help, my triggers (with hardcoded values) doesn't have quote for the parameters, I.e: -F token=xxxx -F ref=master  
> **username_1**: Just in case, are you talking about hosted gitlab or on premise gitlab instance ?  
> **username_0**: I’m using the hosted GitLab.  
> **username_1**: Then we can't even dig in the logs to understand why it fails, you should really open a case at gitlab.com as they are the only ones able to see where and why it fails in the requests  

---

## 1 answers

### Answer by username_2 on 2019-01-16. Score: 2

In your job, I noticed the below curl command, where two things need to be corrected:

token=$CI_JOB_TOKEN - this TOKEN should be generated in project B under Settings -> CI/CD -> Pipeline triggers (Add triggers)
"ref=$CI_COMMIT_REF_NAME" - this is pointing to a branch with name $CI_COMMIT_REF_NAME on project B and this will only execute if it find a project with that branch name, so if you are trying to trigger it on master branch or any specific branch, you should replace it with something like -F "ref=master" in your curl command

 - curl -X POST -F "token=$CI_JOB_TOKEN" -F "ref=$CI_COMMIT_REF_NAME" https://gitlab.com/api/v4/projects/1234/trigger/pipeline

I use the same trigger with few variables to execute one of my job in another project
- "curl -k -X POST -F token=$PROJECT_B_TOKEN -F ref=master -F variables[PROJECT_NAME]=$CI_PROJECT_NAME -F variables[TAG]=$CI_BUILD_REF_NAME -F variables[SOME_VARIABLE_IDENTIFIER]=DevOps -F variables[USER]=$GITLAB_USER_LOGIN https://gitlab.mycompany.com/api/v4/projects/1234/trigger/pipeline"

The person who created in token in project B, needs to be owner in project A to execute this trigger, else it fails with a 404 message.


---

