I have two repositories in gitlab first one with the main project, the second one with autotests. There is Jenkins pipeline, with the following configurations:
Build triggers:
Poll SCM Schedule: * * * * *
Definition: Pipeline script from SCM
SCM: Git
Repositories:
Repository URL: https://gitlab.com/App/Application.git
Credentials: Creds/******
Branches to build:
Branch Specifier (blank for ‘any’): */master
Repository browser: Auto
Script Path: pipelines/Jenkinsfile
The contents of 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
}
When I merge into the master of main Application project, pipeline starts in a minute and passes or fails one time as it should be. But when I merge into the master of Autotests repository, pipeline starts in a minute then it starts in a minute one more time then it starts in a minute over and over again while pipeline is still running. How to fix it?