I merged this as vars/gitCheckout.goovy add this as library into the jenkins
def call(String branch = '*/master') {
checkout([$class: 'GitSCM',
branches: [[name: ${branch}]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: false,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false]],
submoduleCfg: [],
userRemoteConfigs: [[url: 'https://my-server.com/some/project.git']]])
}
Calling this method as below from jenkins Pipeline Script:
@Library('jenkins-library@master') _
pipeline {
agent { label 'my-server' }
stages {
stage('Git Checkout') {
steps {
gitCheckout()
}
}
}
}
This fails with error java.lang.NoSuchMethodError: No such DSL method '$' found among steps [ArtifactoryGradleBuild, MavenDescriptorStep, ....
I tried $branch, params.branch, but it didn't work, the code otherwise works if I don't use parameter and hardcode the branch name. Also, whenever I make any update to this .groovy script, should I test it by merging and running it as jenkins job? is there any other way to test before merging the groovy script ?