Jenkins管道仍在运行,每分钟都会触发一次

时间:2018-08-07 06:37:23

标签: jenkins continuous-integration jenkins-pipeline

gitlab中有两个存储库,一个存储库包含主项目,第二个存储库包含自动测试。 Jenkins管道具有以下配置: **定义:来自SCM的管道脚本

SCM:Git

存储库:

存储库URL:https://gitlab.com/App/Application.git

凭据:凭据/ ******

要建立的分支机构:

分支说明符(“ any”为空白):* / master

资源库浏览器:自动

脚本路径:管道/ Jenkinsfile ** Jenkinsfile的内容:

try {
    node('Slave') {
        stage('Build') {
            dir('Backend') {
                git url: "https://$gitRepo", branch: 'master', credentialsId: gitlabCredentialsId

                def commitHash = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
                version = "${getDateTime()}-$commitHash"

                sh 'chmod +x gradlew && ./gradlew clean build --no-daemon'


                withCredentials([usernamePassword(credentialsId: gitlabCredentialsId,
                        passwordVariable: 'GITLAB_PASSWORD', usernameVariable: 'GITLAB_USERNAME')]) {
                    sh("docker login $registryName -u $GITLAB_USERNAME -p $GITLAB_PASSWORD")
                }

                docker.withRegistry("https://$registryName") {
                    def image = docker.build(imageName)
                    image.push(version)
                    image.push('latest')
                }
                sh 'docker system prune -af || true'
            }
        }

        stage('Integration tests') {
            dir('Autotests') {
                try {
                    url: "https://$autotestsGitRepo", branch: 'master', credentialsId: gitlabCredentialsId

                    withCredentials([usernamePassword(credentialsId: gitlabCredentialsId,
                            passwordVariable: 'GITLAB_PASSWORD', usernameVariable: 'GITLAB_USERNAME')]) {
                        sh("docker login $registryName -u $GITLAB_USERNAME -p $GITLAB_PASSWORD; docker-compose pull backend; docker-compose up -d")
                        waitUntilAppIsUp(localhost)
                        sh('./gradlew clean test')
                    }

                } finally {
                    sh("docker-compose down")
                    step([$class: 'JUnitResultArchiver', keepLongStdio: true, testResults: 'build/test-results/test/*.xml'])
                }
            }
        }

        stage('Staging deployment') {
            withCredentials([usernamePassword(credentialsId: gitlabCredentialsId,
                    passwordVariable: 'GITLAB_PASSWORD', usernameVariable: 'GITLAB_USERNAME')]) {
                sshagent(credentials: [sshInstanceCredentialsId]) {
                    dir('Backend') {
                        sh "scp -o StrictHostKeyChecking=no docker-compose.yml $instanceHost:"
                        sh "ssh -o StrictHostKeyChecking=no $instanceHost 'docker login $registryName -u $GITLAB_USERNAME -p $GITLAB_PASSWORD; docker-compose pull backend; docker-compose up -d'"
                        waitUntilAppIsUp(stagingHost)
                    }
                }
            }
        }
    }
} catch (e) {
    throw e
}

当我合并到主应用程序项目的母版中时,管道在一分钟内启动,并且一次通过或失败了一次。 但是,当我合并到Autotests存储库的主数据库中时,管道在一分钟内启动,然后又在一分钟内启动,然后在管道仍在运行时一遍又一遍地启动。 如何解决?

0 个答案:

没有答案