I have a jenkins multibranch-pipeline. Apparently it checked out the main repo successfully (files are visible in the workspace).
But then I called this method. Goal was to check out (in a dedicated subfolder) the following repository and the same branch that I checked out of the main repo (e.g. if main repo is checked out at "my-target-branch-name" then "bar" repo should also try to check out branch "my-target-branch-name", or "master" as fallback. In fact the whole use case is similar if not the same as the one described in the documentation of the resolveScm step (page might load slowly, be patient)
checkout resolveScm(source: git(url: 'git@example.com:foo/bar.git', credentialsId: 'xxx'), targets: [env.BRANCH_NAME, 'master'])
However I got an error:
16:40:38 java.lang.UnsupportedOperationException: must specify $class with an implementation of class jenkins.scm.api.SCMSource
16:40:38 at org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:574)
16:40:38 at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:473)
16:40:38 at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:409)
16:40:38 at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:329)
16:40:38 at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:302)
16:40:38 at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:193)
16:40:38 at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
16:40:38 at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1278)
16:40:38 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1172)
16:40:38 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
16:40:38 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
16:40:38 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
16:40:38 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
16:40:38 at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
16:40:38 Caused: java.lang.IllegalArgumentException: Could not instantiate {source={GIT_AUTHOR_EMAIL=jenkins.donotreply@example.com, GIT_AUTHOR_NAME=Jenkins, GIT_BRANCH=origin/master, GIT_COMMIT=xxx, GIT_COMMITTER_EMAIL=jenkins.donotreply@example.com, GIT_COMMITTER_NAME=Jenkins, GIT_LOCAL_BRANCH=master, GIT_PREVIOUS_COMMIT=yyy, GIT_PREVIOUS_SUCCESSFUL_COMMIT=yyy, GIT_URL=git@example.com:foo/bar.git}, targets=[my-target-branch-name, master]} for org.jenkinsci.plugins.workflow.multibranch.ResolveScmStep
16:40:38 at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:334)
16:40:38 at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:302)
16:40:38 at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:193)
16:40:38 at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
16:40:38 at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1278)
16:40:38 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1172)
16:40:38 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
16:40:38 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
16:40:38 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
16:40:38 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
16:40:38 at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
16:40:38 at fooBar.call(fooBar.groovy:14)
16:40:38 at fooBar.call(fooBar.groovy:258)
16:40:38 at ___cps.transform___(Native Method)
...
Where did I go wrong?
Here is the complete definition of Jenkinsfile:
pipeline {
agent { label 'small || big' }
stages {
stage('Build') {
steps {
sh "ls -la"
sh "rm -rf secondrepo && mkdir secondrepo"
dir('secondrepo') {
checkout resolveScm(source: git(url: 'git@example.com:foo/bar.git', credentialsId: 'xxx'), targets: [env.BRANCH_NAME, 'master'])
}
}
}
}
}