我的Jenkins管道中有以下阶段:
stage('Update Android SDK') {
withEnv(['ANDROID_HOME=/Users/Shared/android-sdk-macosx',
'PATH=$ANDROID_HOME:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH'
]) {
sh 'echo y | android update sdk --no-ui --all --filter platform,tool,platform-tool,extra-android-m2repository'
}
这曾经很完美。但是,我刚刚更新到Jenkins 2.44和最新的Pipeline插件,从那时起,android
命令就不再运行了。这是来自jenkins日志的错误消息:
+ android update sdk --no-ui --all --filter platform,tool,platform-tool,extra-android-m2repository
/Users/Jenkins/.jenkins/workspace/d_release-3-0-3dummy.1gpbab-FJUYVCADYU5YVX7LNYATQTVORNDAKFSYICGSZRW4QXTUW5E2OMEQ@tmp/durable-f249f287/script.sh: line 2: android: command not found
并且它不仅仅是android
。它看起来像一些安全设置已经改变或某些东西,某些命令不能再通过sh
管道命令运行。例如,echo
和pwd
仍有效,但which
或ls
不会:
+ echo /Users/Shared/android-sdk-macosx
/Users/Shared/android-sdk-macosx
++ which android
/Users/Jenkins/.jenkins/workspace/d_rel/script.sh: line 2: which: command not found
+ echo
[Pipeline] sh
[d_rel] Running shell script
+ pwd
/Users/Jenkins/.jenkins/workspace/d_rel
[Pipeline] sh
[d_rel] Running shell script
+ ls -la /Users/Shared/
/Users/Jenkins/.jenkins/workspace/d_rel/script.sh: line 2: ls: command not found
(我在上面的代码段中用d_release-3-0-3dummy.1gpbab-FJUYVCADYU5YVX7LNYATQTVORNDAKFSYICGSZRW4QXTUW5E2OMEQ@tmp/durable-f249f287
替换了字符串d_rel
,以提高可读性。)
答案 0 :(得分:2)
尝试以下结构:
withEnv(['ANDROID_HOME=/Users/Shared/android-sdk-macosx',]) {
withEnv(["PATH+ADK=${env.ANDROID_HOME}/tools:${env.ANDROID_HOME}/platform-tools"]) {
sh 'echo y | android update sdk --no-ui --all --filter platform,tool,platform-tool,extra-android-m2repository'
}
}
我不认为$ANDROID_HOME
会正确扩展。使用刚刚定义的变量的example位于官方管道示例文档中。
PATH+XYZ
似乎是追加$PATH
的{{3}}方法。