user2781150
user2781150

Reputation: 199

Can we re-trigger the gitlab pipeline?

After creating merge request in GitLab, merge request got failed and jenkins has deleted the failed job logs due to retention period defined under jenkins job. Now, i want to re-trigger that specific merge request only from gitlab so that it will trigger the merge request job in jenkins. Is it possible ? If yes, how can i do the same ?

P.S. There is a pipeline defined from Gitlab to Jenkins. Whenever a merge request get creates in gitlab, it triggers the Jenkins Merge Request job which merge the specific changes to the git master branch.

Upvotes: 10

Views: 13082

Answers (3)

Wayne Kaskie
Wayne Kaskie

Reputation: 3483

Adding on the existing answers, note that you can override GitLab CI variables like CI_PIPELINE_SOURCE = 'merge_request_event' to specifically trigger your MR pipeline against a branch.

Upvotes: 0

msmosavar
msmosavar

Reputation: 121

  1. Go to the merge request page.
  2. In the tabs section (next to Overview), Go to the Pipelines tab.
  3. Click on the button Run pipeline.

Upvotes: 10

Baklap4
Baklap4

Reputation: 4202

Yes you can retrigger the Gitlab Pipelines! There are two options available:

  1. Use the UI
  2. Use the Gitlab Api

Using the UI

  1. Within in your project go to CI / CD: https://gitlab.com/{user/organization}/{project}/pipelines
  2. Then click on the green button Run Pipeline
  3. Select the branch you made the merge request for.
  4. Hit the Create Pipeline button.

This will create and run a gitlab pipeline.

Using the API

  1. Make sure you have a token available which can use the Gitlab API.
  2. Make a POST call to gitlab.com/projects/:id/trigger/pipeline
    1. You can run a curl command to do this
    2. curl -X POST -F token=TOKEN -F ref=BRANCHNAME https://gitlab.com/api/v4/projects/7471909/trigger/pipeline
      
    
    

If you want to trigger a build manually in Jenkins you can also make use of an api in combination with a parameterized build:

curl -X POST JENKINS_URL/job/JOB_NAME/build --user USER:TOKEN  --data-urlencode json='{"parameter": [{"name":"branch", "value":"master"}]}'

The parameter will be the branch to build; eg the branch for your merge request.

Upvotes: 6

Related Questions