简体   繁体   中英

Jenkins - Git polling in custom workspace when checkout is skipped

I have a Jenkins pipeline to compile and deploy the software, and I am using Bitbucket plugin for polling and trigger the pipeline being integrated with Bitbucket Cloud.

checkout(poll: true, scm:[$class: 'GitSCM',  
         branches: [[name: "my_branch"]], 
         extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "my_dir"]], 
         userRemoteConfigs: [[credentialsId: "$credentialsId", url: "my_repo"]]

The Jenkinsfile is outside the software repo and I am using custom directories defined at the stage level for checkout.

The pipeline includes something like 'Checkout', 'Build', 'Deploy1' 'Deploy2' being able to skip stages.

All good if fully run at once, but if the 'Checkout' stage is skipped the polling is ruined as it is looking in the Jenkins job workspace in this case and ignores the custom directories.

I have tried many things, nothing supported by Jenkins I could find, maybe you have an idea for an workaround.

To make it simple

properties([pipelineTriggers([pollSCM("* * * * *")])])

pipeline {
    parameters {
        booleanParam(name: 'UPDATE_SOURCES', defaultValue: True)
    }
    stages {
        stage('Checkout') {
            agent {
                label 'agent_name'
            }
            when {
                expression { return params.UPDATE_SOURCES }
            }
            steps {
                dir("some_full_path_dir") {
                    script {
                        checkout(poll: true, scm:[$class: 'GitSCM', branches: [name: "branch_name"], 
                            userRemoteConfigs: [[credentialsId: "whatever", url: "repo_url"]]
                        ])
                    }
                }
            }
        }
    }
}

If this stage is skipped it will ignore for next build 'some_full_path_dir' from polling, it will only check for C:\Jenkins\etc\etc where is the default workspace. If this stage is run, everything is ok. As I said, I am looking for an ingenious workaround, there is no official solution for that

If this stage is skipped it will ignore for next build 'some_full_path_dir' from polling, it will only check for C:\Jenkins\etc\etc where is the default workspace

That means you must repeat in your other stage (the one executed when the stage('Checkout') is skipped)

steps {
                dir("some_full_path_dir") {

That way, your other stage would also operate in the same custom folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM