1

我在使用Jenkins聲明性管道在Docker容器中運行shell命令時遇到問題。使用碼頭工作流程插件。它似乎找不到命令'貓',暗示路徑問題。我已經將任務限制在一個簡單的任務(env shell命令)中,在一個非常簡單的圖像(高山)中,並驗證了/ bin/cat的工作原理。我的錯誤/誤解是什麼?Jenkins碼頭工作流程插件在沒有PATH的情況下執行

更新:我包括詹金斯生成的整個命令。我沒有添加所有這些額外的參數,由於某些原因,詹金斯似乎將他們注入我的控制之外。

$ docker run -t -d -u 496:493 -w /jenkins/workspace/[email protected] -v /jenkins/workspace/[email protected]:/jenkins/workspace/[email protected]:rw -v /jenkins/workspace/[email protected]@tmp:/jenkins/workspace/[email protected]@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat alpine 
[Pipeline] // withDockerContainer 
[Pipeline] } 
[Pipeline] // node 
[Pipeline] } 
[Pipeline] // stage 
[Pipeline] } 
[Pipeline] // withEnv 
[Pipeline] } 
[Pipeline] // withCredentials 
[Pipeline] } 
[Pipeline] // node 
[Pipeline] } 
[Pipeline] // withEnv 
[Pipeline] End of Pipeline 
java.io.IOException: Failed to run image 'alpine'. Error: docker: Error response from daemon: Container command 'cat' not found or does not exist.. 
at org.jenkinsci.plugins.docker.workflow.client.DockerClient.run(DockerClient.java:125) 

這裏是我的流水線階段:

stage("test") { 
    agent { 
    docker { 
     image 'alpine' 
     label 'docker-enabled' 
    } 
    } 
    steps { 
    sh 'env' 
    } 
} 
+0

如果你在linux上運行,那麼'cat/etc/issue'的結果是什麼? – Avi

+0

嘗試運行'echo $ PATH'來查看路徑是什麼。如果路徑沒有正確設置。 '搬運工運行--name ALP -dt高山cat'和'搬運工EXEC ALP SH -c 「ENV」'給我: 'HOSTNAME = a2b6eeb0788a SHLVL = 1個 HOME = /根 PATH =的/ usr /本地/ sbin:/ usr/local/bin:/ usr/sbin:/ usr/bin:/ sbin:/ bin PWD =/ ' – Rik

+0

這是Jenkins特定的失敗。當我從命令行運行時,Cat在執行路徑上。要求輸出 - '$搬運工運行-id --entrypoint貓高山3719b36a40ecc36eada4674def442b2140f22ed2aec030390acd2ef838763722 $搬運工EXEC 3719貓的/ etc /問題 歡迎高山的Linux 3.4內核 \ r上的\ M(\ L)' –

回答

0

問題通過升級到碼頭工人流水線插件的版本1.10解析(從1.9.1)。工作代碼:

pipeline { 
    agent none 
     stages { 
     stage('Example') { 
      agent { 
       docker { 
        label 'docker' 
        image 'alpine'      
       } 
      } 
      steps { 
       sh 'env' 
      } 
     } 
    } 
} 
相關問題