在jenkins中通过运行docker image访问工作区文件

wnvonmuf  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(164)

我有一个jenkins管道,它运行保存在Dockerimage中的一个脚本。来自Dockerimage的脚本需要一个克隆的github存储库才能运行。因此,所需的存储库被克隆,然后我启动脚本(它带一个参数path to the local copy of repo).我的问题是我在dockerExecute节运行容器后,我可以在我的Jenkins Pipeline工作空间中访问存储库的本地副本吗?

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"
   '''
   }
  }
 }
}
ws51t4hk

ws51t4hk1#

似乎有一个名为dockerVolumeBind的属性,因此您应该能够使用该属性将工作区挂载到容器中。

相关问题