Where can I find the pom.xml file of a git repo cloned using mavenJob

8 views
Skip to first unread message

Charles Moulliard

unread,
Dec 11, 2020, 11:36:01 AM12/11/20
to job-dsl-plugin
Hi,

I cannot find the pom.xml    using the following syntax

    scm {
        git {
            remote {
                url 'https://github.com/snowdrop/spring-boot-bom'
                branch '$TAG'
            }
        }
    }

    preBuildSteps {
            systemGroovyCommand '''\
              import jenkins.model.Jenkins

              def jenkins = Jenkins.getInstanceOrNull()
              def item = jenkins.getItemByFullName("check-bom-dependencies")
              
              // get workspacePath for the job Item
              def workspacePath = jenkins.getWorkspaceFor (item)
              println workspacePath.toString()
              
              def wksPathString = workspacePath.toString()
              def src = new File(wksPathString + "/pom.xml")

as we got his error 

java.io.FileNotFoundException: /var/lib/jenkins/jobs/check-bom-dependencies/workspace/pom.xml (No such file or directory)

Where is then located the pom.xml file when the job runs using a jnlp kubernetes pod ?

Regards

Charles

Charles Moulliard

unread,
Dec 11, 2020, 4:40:42 PM12/11/20
to job-dsl-plugin
That fails too even if I use the WORKSPACE env

import jenkins.model.Jenkins
              import static groovy.io.FileType.*
              import hudson.EnvVars
              
              def jenkins = Jenkins.getInstanceOrNull()
              EnvVars envVars = build.getEnvironment(listener);
              
              def workspace = envVars.get('WORKSPACE')
              println "WKS: $workspace"
              
              println "Backup the pom.xml file"
              def src = new File("$workspace/pom.xml")
              def dst = new File("$workspace/pom.xml.bak")

Question: Should I find the Node/Agent where the code is running ?

Charles Moulliard

unread,
Dec 12, 2020, 7:57:13 AM12/12/20
to job-dsl-plugin
Find the solution after reading this : https://stackoverflow.com/questions/31794545/access-files-on-a-node-slave-from-jenkins-master-using-groovy
That should be documented that "systemGroovyCommand " runs on master only and not slave !!!!

Reply all
Reply to author
Forward
0 new messages