jenkins管道sh步节点未找到

时间:2016-12-14 00:45:08

标签: jenkins jenkins-pipeline

我有以下sh步骤在Jenkins管道上执行一些命令,请注意npm installpackage.json安装bower以便以后的命令工作

    sh """
    . .env/bin/activate
    . ${JENKINS_HOME}/nvm_init.sh
    npm install
    node --version
    which node
    echo $PATH
    export PATH=\$(npm bin):$PATH
    echo $PATH
    which bower
    which node
    node --version
    bower install
    """

输出从npm install开始,如下所示:

+ npm install
npm WARN goconnect@0.0.1 No repository field.
npm WARN goconnect@0.0.1 No license field.
+ node --version
v6.9.2
+ which node
/data/jenkins/.nvm/versions/node/v6.9.2/bin/node
+ echo /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
+ npm bin
+ export PATH=/data/jenkins/workspace/GoConnect_feature_jenkins2-KGJYBCCDJPBPOLJ2K2Q4JVQP6TKHIVKXYDJZ4WUMFHTSSDIZWCAQ/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
+ echo /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
+ which bower
/data/jenkins/workspace/GoConnect_feature_jenkins2-KGJYBCCDJPBPOLJ2K2Q4JVQP6TKHIVKXYDJZ4WUMFHTSSDIZWCAQ/node_modules/.bin/bower
+ which node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1

以下是我不明白的一些事情:

  1. 注意第二个echo $PATH,它与之前的路径相同,但不包含export PATH=\$(npm bin):$PATH
  2. 之前的前缀
  3. 最后which node没有用,为什么?

1 个答案:

答案 0 :(得分:2)

感谢同事@ john-carter指出,在没有逃避美元符号的情况下,groovy将在执行脚本之前进行评估。

sh """
. .env/bin/activate
. ${JENKINS_HOME}/nvm_init.sh
npm install
node --version
which node
echo $PATH
export PATH=\$(npm bin):\$PATH
echo $PATH
which bower
which node
node --version
bower install
"""