简体   繁体   English

在 jenkins 管道上找不到 mvn 命令

[英]mvn command not found on a jenkins pipeline

I am really new with Jenkins and maven projects and starting to drive me crazy even with a simple sample project using https://github.com/jglick/simple-maven-project-with-tests.git我真的是 Jenkins 和 maven 项目的新手,即使使用https 的简单示例项目也开始让我发疯://github.com/jglick/simple-maven-project-with-tests.git

Also using the Pipeline sample script GitHub + Maven from Jenkins还使用流水线示例脚本 GitHub + Maven 来自 Jenkins

stages {
      stage('Build') {
         steps {
            // Get some code from a GitHub repository
            git 'https://github.com/jglick/simple-maven-project-with-tests.git'

            // Run Maven on a Unix agent.
            sh "mvn -Dmaven.test.failure.ignore=true clean package"

But i'm getting the next error:但我收到下一个错误:

+ mvn -version
/var/lib/jenkins/workspace/app-maven@tmp/durable-dba02bb4/script.sh: line 1: mvn: command not found

I found an article which says to use this method for save the mvn path on a variable and use it:我发现一篇文章说使用此方法将 mvn 路径保存在变量上并使用它:

steps {
    // Get some code from a GitHub repository
    git 'https://github.com/alvarosjf/maven-app.git'

    // Run Maven on a Unix agent.
    def mvnHome = tool name: '3.6.3', type: 'maven'
    sh "${mvnHome}/bin/mvn -version"
    //sh 'mvn -version'

But this is even worst showing an error at the startup但这更糟糕,在启动时显示错误

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 5: Not a valid stage section definition: "def mvnHome = tool name: '3.6.3', type: 'maven'". Some extra configuration is required. @ line 5, column 7.
         stage('Build') {
         ^

1 error

Any trick to try and use a simple jenkins pipeline with Github webhooks + maven?尝试使用带有 Github webhooks + maven 的简单 jenkins 管道的任何技巧?

your pipeline code seems to be correct, but you need the used tool (in your script, maven in version 3.6.3) to be configured within Jenkins itself.您的管道代码似乎是正确的,但您需要在 Jenkins 本身中配置使用的工具(在您的脚本中,版本 3.6.3 中的 maven)。

This can be done via:这可以通过以下方式完成:

"Manage Jenkins -> Configure Tools", within the maven section, add a new instance (choose any name you want, use this name also in your pipeline script tool name: 'your-name' type: 'maven' ) leave the rest as it is, which will install maven automatically via downloading from apache servers “管理 Jenkins -> 配置工具”,在 maven 部分中,添加一个新实例(选择您想要的任何名称,也在您的管道脚本tool name: 'your-name' type: 'maven' )离开 rest实际上,它将通过从 apache 服务器下载自动安装 maven

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM