How do you provide a managed file to a Jenkins build using docker.image?

1.1k Views Asked by At

I am trying to use Jenkins Pipelines to build a Maven Java project and deploy its artifacts into Nexus. The Nexus credentials are managed by Jenkins, so I need Jenkins to provide the Maven settings.xml file. My pipeline uses docker to run the build. My Jenkinsfile looks like:

node('docker') {
   git '[email protected]:myorg/myproject.git'

   stage 'Build and Test' 
   // This throws: java.lang.UnsupportedOperationException: Refusing to marshal org.codehaus.groovy.runtime.InvokerInvocationException for security reasons
    //configFileProvider([configFile(fileId: '7d6efcd2-ff3d-43dc-be40-898dab2bff64', variable: 'MYSETTINGS')]) {
    //    sh 'cp ${MYSETTINGS} mysettings.xml'
    // }

    docker.image('maven:3.3.9').inside {
        // sh 'mvn -s mysettings.xml -U -e clean deploy'
        // This fails trying to access AWS ECR (???)
        withMaven(mavenSettingsConfig: '7d6efcd2-ff3d-43dc-be40-898dab2bff64') {
            sh 'mvn -U -e clean deploy'
    }
}

So far I am unable to provide the correct maven settings. There are some 'Knows limitation' on the withMaven (Maven Pipeline Plugin, https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Maven+Plugin)

Is there a workaround ? I tried to use the configFileProvider, but it throws UnsupportedOperationException because of security reasons.

0

There are 0 best solutions below