For loop not accepted in JCasc jobdsl
See original GitHub issueYour checklist for this issue
- [ x ] Jenkins version
- [ x ] Plugin version
- [ x ] OS
I am using the Jenkins helm chart to deploy Jenkins on Kubernetes. Helm chart version 1.23.0. (There have been a lot of updates on the chart lately, the version is from last week).
- Jenkins Version: lts
- JCasc Version: 1.41
- OS: Official Jenkins docker image
Description
I am inserting a jobdsl script with a loop to generate a couple of multibranch jobs. I am using helm to inject these values. The helm chart then mounts this script locally. Everything is correctly inserted. The following lines show a cat
of the inserted script:
root@jenkins-5969d5b49-z8chv:/# cat /var/jenkins_home/casc_configs/jobs.yaml
jobs:
- script: >
def scriptpaths = ['one','two']
for( i in scriptpaths) {
multibranchPipelineJob("${i}") {
branchSources {
git {
id("${i}") // IMPORTANT: use a constant and unique identifier
remote('git@xxxxxxxx')
credentialsId('cloud-jenkins-ssh-private-key')
includes('dev')
}
}
orphanedItemStrategy {
discardOldItems {
numToKeep(20)
}
}
}
}
When executing through jcasc the following error is thrown:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script: 1: expecting EOF, found 'for' @ line 1, column 33.
def scriptpaths = ['one','two'] for( i in scriptpaths) {
^
1 error
[....]
When I do a copy & paste of the job script, paste it manually into a jobdsl build job, everything works.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Pass Variable on a Per-File Basis in Jenkins Configuration as ...
In the example above, the SUPERHERO variable looks to be a global, but I need a way to reuse the same groovy include...
Read more >jenkinsci/configuration-as-code-plugin - Gitter
I've been looking up a lot of documentation about JCasC and Job DSL plugin. ... Jenkins sees the folder as job but will...
Read more >Different behavior with configure when looping vs using each
Is something special being done in each that's not being done during the for that the Job DSL code runs the configure block...
Read more >Jenkins Tutorial: Implementing a Seed Job - HappyCoders.eu
2.1 Loading the Jenkins Job DSL code from the project repository ... Otherwise, you get the error message "script not yet approved for...
Read more >Jenkins Configuration as Code (JCasC) together with JobDSL ...
Unflexible configurations, because everything must fit for everybody (all-in-one instances for whole companies); No real existing backup ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think you’re trimming whitespace,
can you try with
|
instead of>
after yourscript:
@njtman as I mentioned it matters with YAML literal you use.
Your best bet is
|
or|-
again see the https://yaml-multiline.info/