Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jenkins infinite loop due to Poll SCM and commit on release #297

Closed
craigtmoore opened this issue Mar 27, 2019 · 2 comments
Closed

Jenkins infinite loop due to Poll SCM and commit on release #297

craigtmoore opened this issue Mar 27, 2019 · 2 comments

Comments

@craigtmoore
Copy link

I'm using the gradle-release plugin in my gradle projects, and I'm trying to add it to Jenkins to perform a release after each commit on the release branch. However, this causes an infinite loop in Jenkins, where:

  1. Jenkins polls SCM and sees a new commit, triggering a new build
  2. gradle-release plugin performs the release updating the gradle.properties file with the new SNAPSHOT version number.
  3. Jenkins polls SCM and sees a new commit, triggering a new build
  4. gradle-release plugin performs the release updating the gradle.properties file with the new SNAPSHOT version number.
    ...

So basically, I expected the gradle-release plugin to see that the last commit was caused by itself and that it should not perform a release. What am I missing here? I suppose as a work around, I can look at the git log and see if the last commit was due to a release and skip the 'release' stage of the build. however, I believe that'd complicate my Jenkinsfile unnecessarily.

@Hillkorn
Copy link
Collaborator

The release plugin doesn't check it. You could add that check to your build.gradle but I'm not sure if it makes sense to have that kind of check in the plugin as it might become quite complex because of messaage/tag customization.

@craigtmoore
Copy link
Author

OK, I've found a work around by adding a 'when' condition to the 'Release' stage of my Jenkinsfile.

  • 'utils' is the name of the component being released

  • '[Gradle Release Plugin]' default commit message prefix of the release plugin.

      stage('Release') {
          when {
              expression {
                  def branch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
                  def lastCommit = sh(script: 'git log -n 1 --oneline', returnStdout: true).trim()
                  return branch == 'dragon' && !(lastCommit.contains("[Gradle Release Plugin]")
                          && lastCommit.contains("utils-"))
              }
          }
          steps {
              sh "cd services/common/utils && ./gradlew release -Prelease.useAutomaticVersion=true"
              script {
                  isRelease = true
              }
          }
      }
    

It works if the build is triggered after a release, then it will not build. I'm thinking of moving it to the front of the pipeline so it doesn't compile/unit test either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants