bash Jenkins Pipeline sh:找不到命令 - 某些命令现在不可用吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42036463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jenkins Pipeline sh: command not found - are certain commands not available now?
提问by Aphex
I have the following stage in my Jenkins pipeline:
我的 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'
}
This used to work perfectly. However, I just updated to Jenkins 2.44 and the latest Pipeline plugins and since then, the android
command doesn't run anymore. Here's the error message from the jenkins log:
这曾经完美地工作。但是,我刚刚更新到 Jenkins 2.44 和最新的 Pipeline 插件,从那时起,该android
命令不再运行。这是詹金斯日志中的错误消息:
+ 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
And it isn't just android
. It looks to me like some security setting has changed or something, and certain commands can't run via the sh
pipeline command anymore. For example, echo
and pwd
still work, but which
or ls
don't:
它不仅是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
(I've replaced the string d_release-3-0-3dummy.1gpbab-FJUYVCADYU5YVX7LNYATQTVORNDAKFSYICGSZRW4QXTUW5E2OMEQ@tmp/durable-f249f287
with d_rel
in the snippet above to improve readability.)
(我把它换成字符串d_release-3-0-3dummy.1gpbab-FJUYVCADYU5YVX7LNYATQTVORNDAKFSYICGSZRW4QXTUW5E2OMEQ@tmp/durable-f249f287
与d_rel
上述以提高可读性片段。)
What changed? If certain commands are restricted now, what can I do to enable all commands to run?
发生了什么变化?如果某些命令现在受到限制,我该怎么做才能使所有命令都能运行?
采纳答案by Grisha Levit
Try something structured like:
尝试一些结构如下:
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'
}
}
I don't think $ANDROID_HOME
will get expanded correctly otherwise. An exampleof using a variable that was just defined is in the official Pipeline Examples doc.
$ANDROID_HOME
否则我认为不会正确扩展。使用刚刚定义的变量的示例在官方管道示例文档中。
The PATH+XYZ
thing seems to be the suggestedway to append to $PATH
.
的PATH+XYZ
事情似乎是提出要追加到的方式$PATH
。