Accessing workspace files from running docker image in jenkins

Viewed 18

I have a jenkins pipeline that runs a script saved in the Dockerimage. The script from the Dockerimage needs to have a cloned github repository in order to run. So desired repo is cloned and then I launch the script (it takes a parameter of the path to the local copy of the repo). My question is after I am in dockerExecute section running the container, can I access the local copy of the repo in my jenkins pipeline workspace?


node() {

stage('Clone GITHUB repo') {
   git branch: 'main', credentialsId:'GITHUB_TOKEN_CRED_ID', url: 'https://${GH_HOSTNAME}/${GH_ORG_NAME}/${GH_REPO_NAME}.git'

}
stage('launch script') {
   dockerExecute(script: this, dockerImage: 'Docker_image_repository'){
   withCredentials([usernamePassword(credentialsId: GITHUB_TOKEN_CRED_ID, usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_AUTH_TOKEN')]) {    
   sh '''
   script -d "path to cloned repo"
   '''
   }
  }
 }
}
1 Answers

It seems there is a property called dockerVolumeBind, so you should be able to mount the workspace to your container with this.

Related