我正在为我的项目设置管道作业,我想做的是设置该作业,每隔两分钟ping通SCM,以检查是否有更改,如果是,则使用管道脚本来构建作业。
这是我的管道作业配置:
和管道脚本:
pipeline {
agent any
options {
disableConcurrentBuilds()
}
tools {
maven 'Maven 3.6'
}
stages {
stage('Git Checkout') {
steps {
sh 'echo "Git Checkout"'
checkout([$class: 'GitSCM', branches: [[name: 'master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'my-credential', url: 'my-git-url']]])
}
}
stage('Maven Build') {
steps {
sh 'mvn clean deploy -s $WORKSPACE/custom-config/settings.xml -Dsettings.security=$WORKSPACE/custom-config/settings-security.xml'
}
}
stage('Maven Build and SonarQube Analysis') {
steps {
withSonarQubeEnv('Sonar Qube') {
sh 'mvn sonar:sonar -Dsonar.projectKey=com.product:backend'
}
}
}
stage('SonarQube Quality Gate') {
steps {
timeout(time: 10, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
}
post {
failure {
mail bcc: '', body: "See ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "Build failed in Jenkins: ${env.JOB_NAME} #${env.BUILD_NUMBER}", to: "my.email@gmail.com";
}
unstable {
mail bcc: '', body: "See ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "Build unstable in Jenkins: ${env.JOB_NAME} #${env.BUILD_NUMBER}", to: "my.email@gmail.com";
}
}
}
一切正常,除了每两分钟触发一次作业,尽管我在脚本中设置的master分支没有任何变化。有人可以在这里帮助我防止此操作。我希望仅在SCM发生变化时才触发作业。非常感谢你!