一千萬個為什麽

搜索

Jenkins:使用Docker作為構建環境的權限問題



我在Ubuntu 16.04機器上安裝了Jenkins。詹金斯本身不在容器中運行。我想要做的只是使用節點圖像調用 yarn install 。所以這裏是我的Jenkinsfile:

pipeline {
    agent any
    stages {
        stage('install node modules...') {
            agent { docker 'node' }
            steps {
                sh 'cd /path/to/package.json; yarn install'
            }
        }
    }
}

很簡單,對吧?

jenkins用戶/組是 112:116 ,並且節點容器的uid是 1000 ,因此yarn process(作為node user 1000運行)不能執行東西,如 mkdir /.config

我嘗試啟動傳遞參數 -u 1000 的節點容器,它在嘗試創建持久目錄時遇到了許可問題。

它看起來像是其中一種問題,我該如何解決這個問題?

詹金斯日誌:

以下是構建開始和失敗的地方。

[Pipeline] sh
[Pipeline_Test_Je[email protected]2] Running shell script
+ docker inspect -f . node
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 112:116 -w /var/lib/jenkins/workspace/Pipeline_Test_Je[email protected]2 -v /var/lib/jenkins/workspace/Pipeline_Test_Je[email protected]2:/var/lib/jenkins/workspace/Pipeline_Test_Je[email protected]2:rw,z -v /var/lib/jenkins/workspace/Pipeline_Test_Je[email protected][email protected]:/var/lib/jenkins/workspace/Pipeline_Test_Je[email protected][email protected]:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat node
[Pipeline] {
[Pipeline] sh
[Pipeline_Test_Je[email protected]2] Running shell script
+ cd /path/to/package.json
+ yarn install
yarn install v0.24.6
error An unexpected error occurred: "EACCES: permission denied, mkdir '/.config'".
info If you think this is a bug, please open a bug report with the information provided in "/var/lib/jenkins/workspace/Pipeline_Test_Je[email protected]2//yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
[Pipeline] }
$ docker stop --time=1 c1147934ea689f71a449e486282db03338b12182368def31bdf8e8cf179ab46a
$ docker rm -f c1147934ea689f71a449e486282db03338b12182368def31bdf8e8cf179ab46a
[Pipeline]//withDockerContainer
[Pipeline] }
[Pipeline]//node
[Pipeline] }
[Pipeline]//stage
[Pipeline] }
[Pipeline]//node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

轉載註明原文: Jenkins:使用Docker作為構建環境的權限問題

一共有 1 個回答:

我有與節點相同的問題。事情是容器中的文件由“root:root”擁有。嘗試添加docker參數 -u root:root

docker { 
    image 'node:8'
    args '-u root:root'
}