jenkins管道updateGitlabCommitStatus不工作

zbq4xfa0  于 2022-11-02  发布在  Jenkins
关注(0)|答案(2)|浏览(316)

GITLAB_版本:GitLab企业版13.9.3-ee JENKINS_版本:2.263.4
我已经创建了一个jenkins管道,它是由gitlab中的变化触发的,但是它没有更新gitlab的状态。

pipeline {
    agent any
    stages {
       stage('cloning from gitlab'){
           steps{
             git credentialsId: '7d13ef14-ee65-497b-8fba-7519f5012e81', url: 'git@git.MYDOMAIN.com:root/popoq.git'

           }
       }
       stage('build') {
          steps {
             echo 'Notify GitLab'
             updateGitlabCommitStatus name: 'Jenkins-build', state: 'pending'
             echo 'build step goes here'
          }
       }
       stage('echoing') {
           steps{
               echo "bla blaa bla"
           }
       }
       stage(test) {
           steps {
               echo 'Notify GitLab'
               echo 'test step goes here'
               updateGitlabCommitStatus name: 'Jenkins-build', state: 'success'

           }
       }
    }
 }

在gitlab中没有显示任何管道,有什么建议吗?

pokxtpni

pokxtpni1#

我认为您在“option”块中遗漏了一个“gitlabBuilds”命令,该命令声明了您在构建中将要执行的步骤。

options {
    gitLabConnection('xxx-gitlab')
    gitlabBuilds(builds: ['step1', 'step2', 'step3'])
}

然后,您可以使用“updateGitlabCommitStatus”来引用这些步骤,但最好使用“gitlabCommitStatus”命令,如下所示:

pipeline {
agent any
options {
    gitLabConnection('xxx-gitlab')
    gitlabBuilds(builds: ['step1', 'step2', 'step3'])
}
stages {
   stage('step1'){
     steps{
       gitlabCommitStatus(name:'step1') {
         git credentialsId: '7d13ef14-e', url: 'xxxxxxx'
       }
     }  // end steps
   }  // end stage
   stage('step2'){
     steps{
       gitlabCommitStatus(name:'step2') {
         .......
       }
     }  // end steps
   }  // end stage
}
zf9nrax1

zf9nrax12#

pipeline {
agent {
    label 'agent_gradle'
}
options {
    gitLabConnection('Gitlab Jenkins integration API connection test')
    gitlabBuilds(builds: ['step1', 'step2'])
}
stages {
    stage('Build') {
        steps {
            gitlabCommitStatus(name: 'step1') {
                container(name: 'gradle') {
                    echo 'Building the application...'
                }
            }
        }
    }
    stage('Test') {
        steps {
            gitlabCommitStatus(name: 'step2') {
                container(name: 'gradle') {
                    echo 'Testing the application...'
                }
            }
        }
    }

}

}

相关问题