tabeyti / jenkins-jack

Jack into your Jenkins to execute Pipeline scripts, provide Pipeline step autocompletions, pull Shared Library step documenation, run console groovy scripts across multiple nodes, and more! Honestly, not that much more.
Other
98 stars 31 forks source link

‘checkout scm’ cannot be run from Pipeline script #90

Closed modestMouse1 closed 1 year ago

modestMouse1 commented 1 year ago

I'm trying to run a parameterized Pipeline script as follows:

def doGitCheckout(github_url, branch_tag_identifier, github_key) {
  checkout([ 
    $class: 'GitSCM',
    branches: [[name: branch_tag_identifier]], 
    doGenerateSubmoduleConfigurations: false, 
    extensions: [
      [
        $class: 'CloneOption',
        noTags: false,
        shallow: false,
        depth: 0,
        reference: ''
      ],
      [ 
        $class: 'SubmoduleOption', 
        depth: 1, 
        disableSubmodules: false, 
        parentCredentials: true, 
        recursiveSubmodules: true, 
        reference: '', 
        shallow: true, 
        trackingSubmodules: false
      ],
      //[$class: 'GitLFSPull']
    ], 
    submoduleCfg: [], 
    userRemoteConfigs: [[ credentialsId: github_key, url: github_url]]
  ]);
}
/****  PIPELINE ****/
pipeline{
    agent any
    stages{
        stage("Clone & Build") {
            steps{
                print( "repository URL: " + scm.userRemoteConfigs[0].url );
                doGitCheckout(
                    scm.userRemoteConfigs[0].url,
                    'refs/'+params.branchTagIdentifier,
                    'github-key'
                );
            }
        }
    }
    post{
        always{
            script{
                    emailext(
                        body: '''${SCRIPT, template="my-email.template"}''',
                        mimeType: 'text/html',
                        subject: "[Jenkins] ${env.JOB_NAME} [${env.BUILD_NUMBER}] - ${currentBuild.currentResult}",
                        to: '$DEFAULT_RECIPIENTS'
                    );
                cleanWs(deleteDirs: true, disableDeferredWipeout: true);
            }
        }
    }
}

When run from within Jenkins, the script runs fine, when run from VS Code using Jenkins Jack, I get the following error:

ERROR: ‘checkout scm’ is only available when using “Multibranch Pipeline” or “Pipeline script from SCM”
Finished: FAILURE

I'm using GitHub plugin v 1.34.3.