我有一个jenkins管道作业,作业配置从一个回购中提取Jenkinsfile。一旦作业运行并拉出jenkins文件,它就会克隆repo,我可以在工作区的工作区图标中看到它。
现在,当我在Jenkinsfile中执行cd $ {workspace}和ls时,它不会显示任何内容。如何访问Jenkinsfile的repo工作区?或者它只存储Jenkinsfile本身?
这是我的Jenkins文件:
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 repo。它也在工作区中。所以当我这样做时为什么它没有显示文件?
当我进入Jenkins作业管道步骤并在控制台中打开工作区时,我可以在工作区中看到完整的回购,但我似乎无法在作业中访问它。
答案 0 :(得分:1)
尝试使用Jenkins管道语法,例如:
pipeline {
agent { node { label 'master' } }
stages {
stage('After Checkout') {
steps {
sh 'pwd; ls'
}
}
}
}
答案 1 :(得分:1)
您可以checkout scm
将存储库实际签出到工作区,或者只能在主文件的../${env.JOB_NAME}@script
下找到它。
最好总是手动结帐checkout scm
,因为奴隶没有../$env.JOB_NAME@script
文件夹。