1

Can you please help, I have the following scenario and I went through many videos, blogs but could not find anything matching with my use-case

Requirement: To write a CI\CD pipeline in GitLab, which can facilitate the following stages in this order

- verify        # unit test, sonarqube, pages
- build         # package
- publish       # copy artifact in repository
- deploy        # Deploy artifact on runtime in an test environment
- integration   # run postman\integration tests

All other stages are fine and working but for the deploy stage, because of a few restrictions I have to submit an existing Jenkins job using Jenkin remote API with the following script but the problem that script returns an asynchronous response and start the Jenkins job and deploy stage completes and it moves to next stage (integration).

Run Jenkins Job:
    image: maven:3-jdk-8
    tags:
        - java
    environment: development
    stage: deploy
    script:
        - artifact_no=$(grep -m1 '<version>' pom.xml | grep -oP  '(?<=>).*(?=<)')
        - curl -X POST http://myhost:8081/job/fpp/view/categorized/job/fpp_PREP_party/build --user mkumar:1121053c6b6d19bf0b3c1d6ab604f22867 --data-urlencode json="{\"parameter\":[{\"name\":\"app_version\",\"value\":\"$artifact_no\"}]}"

Note: Using GitLab CE edition and Jenkins CI project service is not available.

I am looking for a possible way of triggering the Jenkins job from the pipeline and only on successful completion of the Jenkins job my integration stage starts executing.

Thanks for the help!

manish2aug
  • 113
  • 2
  • 5

1 Answers1

1

Retrieving the status of a Jenkins job that is triggered programmatically through the remote access API is notorious for not being quite convoluted.

Normally you would expect to receive in the response header, under the Location attribute, a url that you can poll to get the status of your request, but unfortunately there are some in-between steps to reach that point. You can find a guide in this post. You may also have a look in this older post.

Once you have the url, you can pool and parse the status job and either sh "exit 1" or sh "exit 0" in your script to force the job that is invoking the external job to fail or succeed, depending on how you want to assert the result of the remote job

Neo Anderson
  • 5,957
  • 2
  • 12
  • 29