Home > Mobile >  Is it possible to call Gitlab Pipeline from Jenkins pipeline and then wait for the results from the
Is it possible to call Gitlab Pipeline from Jenkins pipeline and then wait for the results from the

Time:07-12

I have Gitlab Pipeline for running automation testing(it is done more like a microservice - it runs the test suites depending on the input variables).

Now I have a Jenkins pipeline for the building where I want to replace the "automation test" stage with a call to Gitlab.

What I did now I call the webhook to Gitlab to trigger the automation suite. But since it is a webhook, the automation test stage is always "pass" even if the GitLab pipeline fails.

Is it possible to wait for results in Jenkins, or is it any existing software to handle it?

Thank you!

UPDATE:

pipeline {

stages {
stage('calculate build and deployment') {
  steps {
    script {
    ...
    }
stage('checkArtifactory') {
  steps {
    script {
      ...
    }
  }
}
stage('unit test') {
  steps {
    script {
      ...
    }
  }
}
stage("deploy") {
  
  stages {
    stage('dev deploy') {
      steps{
        script {
            ..
        }
      }
    }
    stage('automated tests') {
      steps{
        script {
          !!!CURL REQUEST TO GITLAB TO TOUCH A WEBHOOK 
        }
      }
    }
  }
}

CodePudding user response:

Instead of using the webhook. Maybe you can consider using the Gitlab API. For example, if I assume you get the Run ID once you trigger a Pipeline through the Gitlab API, you can do another call to check the status of the Pipeline and keep on doing it until the execution ends. This will look something like the one below. Instead of using Groovy you can implement the same with a shell script as well.

stage('automated tests') {
    steps{
      script {
        def buildId = httpRequest 'http://GITLAB_PIPELINE_TRIGGER_URL' // Here I'm using HTTP Request plugin in Jenkins
        timeout(time: 300, unit: 'SECONDS') { // To make sure we don't wait forever
            def doCheck = true
            while(doCheck) {
              def response = httpRequest 'http://GITLAB_JOB_STATUS_URL/$buildId'
              if(response == "Success") {
                  doCheck = false
              } else if (response == "Failure") {
                  error "GITLAB Job failed"
              } 
          }
        }
      }
    }
  • Related