我从https://jenkins.io/doc/book/pipeline/syntax/#tools那里得到了这个例子
管道脚本:
pipeline {
agent any
tools {
maven 'apache-maven-3.3.9'
}
stages {
stage('Example') {
steps {
sh 'mvn --version'
}
}
}
}
apache-maven-3.3.9在我的全局工具配置中定义。
脚本的输出为
Started by user *************
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on SRV-CI-MADE-UNIX in /home/jenkins/workspace/*************
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Tool Install)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Example)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ mvn --version
/home/jenkins/workspace/*************@tmp/durable-d4209a18/script.sh: line 1: mvn: command not found
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
ERROR: script returned exit code 127
Finished: FAILURE
为什么找不到mvn命令?
我知道显然还有其他方法,但这是Jenkins文档本身的示例...
答案 0 :(得分:0)
这是正确的示例(我也对其进行了测试),但是如果您只有master
节点,那么它可以正常工作。
我认为您刚刚在Global Tool Configuration
的{{1}}节点上配置了Maven工具,但是我看到您在master
节点上执行了工作,并且对于该节点还提供正确的Maven配置。
因此,要解决此问题,我想您需要执行以下步骤:
SRV-CI-MADE-UNIX
或agent any
)中提供正确的代理(而不是master
); SRV-CI-MADE-UNIX
中配置的目录中的指定节点上安装Maven或在Global Tool Configuration
中为此节点添加特定的Maven工具位置