对于以下常规代码:
node('worker_node'){
ws("${WORKSPACE}"){
createPropertiesFile()
}
}
def createPropertiesFile(){
try{
sh 'whoami'
def newFile = new File("sonar-project.properties")
newFile.createNewFile()
}catch(Throwable e){
echo "${e}"
}
}
创建两个工作空间:
/app/jenkins/workspace/Test/groovy_closures on worker_node
/app/jenkins/workspace/Test/groovy_closures@2 on worker_node // not sure about the purpose of this work space
但给出以下输出:
Running on worker_node in /app/jenkins/workspace/Test/groovy_closures
[Pipeline] {
[Pipeline] ws
Running in /app/jenkins/workspace/Test/groovy_closures@2
[Pipeline] {
[Pipeline] sh
+ whoami
jenkins
[Pipeline] echo
java.io.IOException: Permission denied
[Pipeline] }
[Pipeline] // ws
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
$ whoami
为所有者提供jenkins
来运行此脚本,如下所示:
User_Jenkins_configuration_on_worker_node
ws("${WORKSPACE}"){
sh "touch file" // creates file in /app/jenkins/workspace/Test/groovy_closures@2 folder but not in /app/jenkins/workspace/Test/groovy_closures folder
}
1)为什么用户jenkins
没有创建文件的权限?如何在詹金斯(Jenkins)中配置用户jenkins
以获得此权限?
2)如何在/app/jenkins/workspace/Test/groovy_closures
中创建文件,而不在/app/jenkins/workspace/Test/groovy_closures@2
中创建文件?