管道脚本尝试在@ 2工作区中创建文件

时间:2019-02-25 20:35:37

标签: java jenkins groovy jenkins-pipeline jenkins-groovy

对于以下常规代码:

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中创建文件?

0 个答案:

没有答案