我有一个 jenkins 管道作业,作业配置从 repo 中提取 Jenkinsfile。一旦作业运行并拉取 jenkinsfile,它就会克隆 repo,我可以在作业的工作区图标中看到它。
现在,当我在 Jenkinsfile 中执行 cd ${workspace} 和 ls 时,它不会显示任何内容。如何访问 Jenkinsfile 的 repo 的工作区?还是它只是存储 Jenkinsfile 本身?
这是我的 Jenkinsfile :
node ("master"){
// Mark the code checkout 'Checkout'....
stage 'Checkout'
sh "pwd ; ls"
}
当我运行它时,我得到以下日志:
> GitHub pull request #282 of commit
> 0045a729838aae0738966423ff19c250151ed636, no merge conflicts. Setting
> status of 0045a729838aae0738966423ff19c250151ed636 to PENDING with url
> https://10.146.84.103/job/test1/ and message: 'Pull request builder
> for this security group pr started' Using context: SG Terraform
> Validate/Plan
> > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository
> > git config remote.origin.url https://github.xxx.net/Terraform/djin-sg/ # timeout=10 Fetching
> upstream changes from https://github.xxx.net/Terraform/djin-sg/
> > git --version # timeout=10 using GIT_ASKPASS to set credentials wsjbuild
> > git fetch --tags --progress https://github.xxx.net/Terraform/djin-sg/
> +refs/heads/*:refs/remotes/origin/*
> > git rev-parse origin/master^{commit} # timeout=10 Checking out Revision 9dd8491b7b18c47eac09cec5a4bff4f16df979bf (origin/master)
> > git config core.sparsecheckout # timeout=10
> > git checkout -f 9dd8491b7b18c47eac09cec5a4bff4f16df979bf First time build. Skipping changelog. [Pipeline] node Running on master in
> /var/lib/jenkins/workspace/test1 [Pipeline] { [Pipeline] stage
> (Checkout) Using the ‘stage’ step without a block argument is
> deprecated Entering stage Checkout Proceeding [Pipeline] wrap
> [Pipeline] { [Pipeline] sh [test1] Running shell script
> + cd /var/lib/jenkins/workspace/test1
> + ls
我的具体问题是,要获取 Jenkinsfile,它会克隆 djin-sg 存储库。它也在工作区中。那么当我执行 ls 为什么它不显示任何文件?
当我进入 Jenkins 作业管道步骤并在控制台中打开工作区时,我可以在工作区中看到完整的存储库,但我似乎无法在工作中访问它。