我在Jenkins中创建了一个PipelineJob,它调用了其他两个Jenkins作业:
pipeline {
agent any
stages {
stage("Trigger disable script approval") {
steps {
script{
build job: 'Tools/Disable_Script_Approval'
}
}
}
stage("Trigger Jobs loading into Jenkins") {
steps {
script{
build job: 'Tools/Seed_Job_Executor'
}
}
}
}
}然后,为了获得DSL中的作业语法,我使用了xml-job-to-job-dsl插件:
pipelineJob("testLior") {
description()
keepDependencies(false)
definition {
cpsScm {
"""pipeline {
agent any
stages {
stage("Trigger disable script approval") {
steps {
script{
build job: 'Tools/Disable_Script_Approval'
}
}
}
stage("Trigger Jobs loading into Jenkins") {
steps {
script{
build job: 'Tools/Seed_Job_Executor'
}
}
}
}
}""" }
}
disabled(false)
configure {
it / 'properties' / 'com.sonyericsson.rebuild.RebuildSettings' {
'autoRebuild'('false')
'rebuildDisabled'('false')
}
}
}我使用了上面的代码,并尝试在JCasC配置中使用(我们正在运行Jenkins,在EKS之上使用helm图表),并创建了这个值文件:
controller:
JCasC:
configScripts:
casc-jobs: |
jobs:
- script: >
pipelineJob('DSL_Seed_Job') {
definition {
cpsScm {
'''pipeline {
agent any
stages {
stage('Trigger disable script approval') {
steps {
script{
build job: 'Tools/Disable_Script_Approval'
}
}
}
stage('Trigger Jobs loading into Jenkins') {
steps {
script{
build job: 'Tools/Seed_Job_Executor'
}
}
}
}
}'''
}
}
}
...
...因此,一旦我运行helm升级,我就会看到Jenkins无法读取JCasC作业配置,并且出现以下错误消息:
2021-10-21 11:04:37.178+0000 [id=22] SEVERE hudson.util.BootFailure#publish: Failed to initialize Jenkins
while scanning a simple key
in /var/jenkins_home/casc_configs/casc-jobs.yaml, line 3, column 3:
pipelineJob('DSL_Seed_Job') {
^
could not find expected ':'
in /var/jenkins_home/casc_configs/casc-jobs.yaml, line 12, column 38:
... build job: 'Tools/Disable_Script_Approval'造成这一错误的原因是什么?我从xml-job-to-dsl-job Jenkins插件获得了DSL语法,所以我不明白我在这里遗漏了什么。
提前谢谢你,
利奥
发布于 2022-01-12 16:09:28
到目前为止,您可能已经知道了这一点,但在我看来,这是一个yaml缩进问题,我认为以"pipelineJob“开头的块应该缩进如下所示:
jobs:
- script: >
pipelineJob('DSL_Seed_Job') {
...
}https://stackoverflow.com/questions/69661317
复制相似问题