Configuration-as-code-plugin: casc reload groovy command breaks jobdsl plugin if executed by pipeline step load()

Created on 14 Dec 2019  ·  9Comments  ·  Source: jenkinsci/configuration-as-code-plugin

Your checklist for this issue

  • [x] Jenkins version: 2.190.3

  • [x] Plugin version: 1.34

  • [x] OS: docker image based on jenkins/jenkins:lts

Description

If jobs section is present in jenkins.yaml, configuration reload fails, both via UI and groovy script. Jobs config works without any issues on init, but fails on reload. CASC_JENKINS_CONFIG is set to url.

Config example:

jobs:
  - script: >
      folder('xxx')

Error: groovy.lang.MissingMethodException: No signature of method: javaposse.jobdsl.plugin.JenkinsDslScriptLoader.customizeCompilerConfiguration() is applicable for argument types: (org.codehaus.groovy.control.CompilerConfiguration) values: [org.codehaus.groovy.control.CompilerConfiguration@67233c11]

Full trace: https://pastebin.com/0A2Mtz8z

bug stale

Most helpful comment

To be honest, that page is quite lacking some important details. Like example of Jenkins CLI command or mention that only system groovy script will work.. Should I maybe just create PR for that? :)

I was able to find the root of this issue: forgot to remove load('reload.groovy') step from test job created by jobdsl 🤦🏻‍♂️ so seed job and reload job were working correctly but then test job was built by branch indexing and breaking jobdsl plugin..

Conclusion: using load pipeline step to run casc reload groovy command effectively breaks jobdsl plugin. Guess it's a lack of permissions, but quite weird that it's affecting jobdsl plugin in such way.

P.S. Maybe it will be useful for someone, my configs for casc reload:

jobdsl for reload job:

job('casc-reload') {
    steps {
        systemGroovyCommand("""
            import io.jenkins.plugins.casc.ConfigurationAsCode;
            ConfigurationAsCode.get().configure()
        """.stripIndent()) {
            sandbox(true)
        }
    }
}

declarative pipeline step to trigger reload:

build('casc-reload')

required permissions in casc:

  scriptApproval:
    approvedSignatures:
      - 'staticMethod io.jenkins.plugins.casc.ConfigurationAsCode get'
      - 'method io.jenkins.plugins.casc.ConfigurationAsCode configure'

All 9 comments

what version of jobdsl are you using?

1.76

Update:

issue is reproducing only if reload using declarative pipeline step load:

reload.groovy file:

import io.jenkins.plugins.casc.ConfigurationAsCode;
ConfigurationAsCode.get().configure()

pipeline step:

load('reload.groovy')

UI, token, script console and freestyle job with 'execute system groovy script' are working just fine.
And after running declarative step above, all other reload methods start failing as well.

Are there any examples on how to trigger casc reload from declarative pipeline? I wasn't able to find any..

For reference, I was able to trigger casc reload from declarative pipeline by creating via jobdsl freestyle job with systemGroovyCommand step and then invoking that job by build step.

Would be nice to trigger reload directly from declarative pipeline though.

still the same error with freestyle reload job: it runs just fine immediately after jenkins start, but after running jobdsl step in another job reload job starts failing and jobdsl step as well. It seems to me that groovy code for reload is somehow breaking jobdsl plugin.

To be honest, that page is quite lacking some important details. Like example of Jenkins CLI command or mention that only system groovy script will work.. Should I maybe just create PR for that? :)

I was able to find the root of this issue: forgot to remove load('reload.groovy') step from test job created by jobdsl 🤦🏻‍♂️ so seed job and reload job were working correctly but then test job was built by branch indexing and breaking jobdsl plugin..

Conclusion: using load pipeline step to run casc reload groovy command effectively breaks jobdsl plugin. Guess it's a lack of permissions, but quite weird that it's affecting jobdsl plugin in such way.

P.S. Maybe it will be useful for someone, my configs for casc reload:

jobdsl for reload job:

job('casc-reload') {
    steps {
        systemGroovyCommand("""
            import io.jenkins.plugins.casc.ConfigurationAsCode;
            ConfigurationAsCode.get().configure()
        """.stripIndent()) {
            sandbox(true)
        }
    }
}

declarative pipeline step to trigger reload:

build('casc-reload')

required permissions in casc:

  scriptApproval:
    approvedSignatures:
      - 'staticMethod io.jenkins.plugins.casc.ConfigurationAsCode get'
      - 'method io.jenkins.plugins.casc.ConfigurationAsCode configure'

Feel free to contribute a PR to improve the docs

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings