我有一个过时的Jenkins实例,我们有很多JobdsL自动化的工作。作为即将到来的Jenkins升级的准备,我们尝试将最后一个手动定义的作业移动到JobDSL。
我们尝试使用以下代码段创建管道作业:
scm {
git {
remote {
credentials '3289472389479'
url 'https://....'
}
branch config[context.config.environmentProfile].branch
extensions {
cleanBeforeCheckout()
}
}
}
这会导致SCM部分的作业配置:
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>https://....</url>
<credentialsId>3289472389479</credentialsId>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/develop</name>
</hudson.plugins.git.BranchSpec>
</branches>
<disableSubmodules>false</disableSubmodules>
<recursiveSubmodules>false</recursiveSubmodules> <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<authorOrCommitter>false</authorOrCommitter>
<clean>false</clean>
<wipeOutWorkspace>false</wipeOutWorkspace>
<pruneBranches>false</pruneBranches>
<remotePoll>false</remotePoll>
<ignoreNotifyCommit>false</ignoreNotifyCommit>
<gitTool>Default</gitTool>
<skipTag>true</skipTag>
<extensions>
<hudson.plugins.git.extensions.impl.CleanBeforeCheckout/>
</extensions>
</scm>
这个作业配置似乎有点无效。在这个工作中,我们尝试使用groovy访问scm配置,但在作业的上下文中没有scm对象。手动保存作业配置后,作业有效并且作业的配置看起来非常不同:
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.0">
<scm class="hudson.plugins.git.GitSCM" plugin="git@2.4.2">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>https://...</url>
<credentialsId>3289472389479</credentialsId>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/develop</name>
</hudson.plugins.git.BranchSpec>
</branches><doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions>
<hudson.plugins.git.extensions.impl.CleanBeforeCheckout/>
</extensions>
</scm>
有没有人经历过这样的行为?目前,此问题阻止我们升级我们最大的Jenkins实例。
非常感谢提示!
更新(确切差异):
执行这个常规代码currentBuild.rawBuild.parent.SCMs.size()
时:
0
1