【问题标题】:Why is the mvn command not found in this declarative jenkins pipeline script?为什么在这个声明性 jenkins 管道脚本中找不到 mvn 命令?
【发布时间】:2019-02-01 08:56:29
【问题描述】:

我从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 文档本身的示例...

【问题讨论】:

    标签: maven jenkins jenkins-pipeline


    【解决方案1】:

    这是正确的示例(我也对其进行了测试),但如果您只有 master 节点,它就可以工作。

    我认为您刚刚在 Global Tool Configuration 中为 master 节点配置了 Maven 工具,但我看到您在 SRV-CI-MADE-UNIX 节点上执行了您的工作,并且对于此节点,您还需要提供正确的 Maven 配置.

    所以,要解决这个问题,我认为您需要执行以下步骤:

    1. 在为其配置了 Maven 工具的管道配置(例如 masterSRV-CI-MADE-UNIX)中提供正确的代理(而不是 agent any);
    2. Global Tool Configuration中配置的同一目录中的指定节点上安装Maven,或在Manage Jenkins -> Manage Nodes -> <YOUR_NODE> -> Configure -> Node Properties -> Tool Locations中添加此节点的特定Maven工具位置

    【讨论】:

    • 嗯,我的master是windows,slave是unix...所以配置同一个目录是不行的。
    • 所以,指定正确的代理并尝试在Node Properties添加Maven工具位置。
    猜你喜欢
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    相关资源
    最近更新 更多