Git Plugin: How can I access files from the repo

I have a Job-DSL job that starts a pipeline script, but it could be any other job that uses the Git plugin to chekcout its files.

// Job-DSL script used with JCASC
pipelineJob("cgfw-kvm-image-sync") {
  definition {
    cpsScm {
      scm {
        git {
          remote {
            url("ssh://git@somehost.com/somerepo.git")
            credentials("git-ssh")
          }
          branch('main')
        }
      }
      scriptPath("some-pipeline.groovy")
    }
  }
}

In some-pipeline.groovy, which is commited in somerepo, Iā€™d like to use other files than just the pipeline script to do something in the job, e.g.:

// some-pipeline.groovy
node {
  stage("stuff") {
    sh script: "jq -r '.data' ????/a_file_from_somerepo.json | bash ????/another_file_from_somerepo.sh"
  }
}

But the workspace is empty. How do I find the files that were checked out by the Git Plugin and use them?

When you use a node step you will get a new workspace. That workspace is empty initially. You can usually do checkout scm and then you will get the main branch checked out and you can then access the files

node {
  stage("stuff") {
    checkout scm
    sh script: "jq -r '.data' ????/a_file_from_somerepo.json | bash ????/another_file_from_somerepo.sh"
  }
}
1 Like