微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Maven管道中使用Maven插件

如何解决如何在Maven管道中使用Maven插件

我在withMaven上使用詹金斯(Jenkins)腰线:

我尝试:

stage('Download binary') {
    steps {
        script {
            def Constants = com.comp.Constants
            withMaven(globalMavenSettingsConfig: 'empty-global-settings',mavenSettingsConfig: Constants.CONfig_SETTINGS_ID) {                  
                // download jar file
                sh "$MVN_CMD org.apache.maven.plugins:maven-dependency-plugin:get --define artifact=${artifact} --define transitive=false"
                sh "$MVN_CMD org.apache.maven.plugins:maven-dependency-plugin:copy --define artifact=${artifact} --define mdep.stripVersion=true --define outputDirectory=${WORKSPACE}"
            }
        }
    }
}

但是我有这个错误

$ docker exec 023505fd08232c4b1e385684169e15195a16d6af31928308374582e757e0e520 env printenv MAVEN_HOME
$ docker exec 023505fd08232c4b1e385684169e15195a16d6af31928308374582e757e0e520 env printenv M2_HOME
$ docker exec 023505fd08232c4b1e385684169e15195a16d6af31928308374582e757e0e520 env /bin/sh -c "which mvn"
[withMaven] Maven installation not specified in the 'withMaven()' step and not found on the build agent
...
hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: MVN_CMD for class: WorkflowScript

我尝试这样做并解决了我的问题(这很奇怪而且很丑):

stage('stub for workaroud') {
    steps {
        script {
            def Constants = com.comp.Constants
            checkoutGitSCM(
                    url: "${Constants.BITBUCKET_URL}/stub.git",tag: Constants.STUB_TAG
                 )
            }
        }
    }
}

很奇怪,如果我添加一个checkoutGitSCM$MVN_CMD的步骤,并且有[withMaven] using Maven installation provided by the build agent with the environment variable MAVEN_HOME=/usr/local/share/maven

编辑:

添加sh "env"命令。在我拥有checkoutGitSCM之前,

MVN_CMD=/home/jenkins/workspace/MyJob@tmp/withMaven10a4d8db/mvn
MVN_CMD_DIR=/home/jenkins/workspace/ODM_Common_XLD_deploy@tmp/withMaven10a4d8db

如果我使用sh "$MVN_CMD_DIR/mvn org.apache.maven.plugins:maven-dependency-plugin:get...不再起作用,则需要在checkoutGitSCM之前使用withMaven

编辑2:

我将FINE的日志级别添加org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution2,结果是:

Sep 04,2020 3:29:45 PM FINE org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution2 obtainMavenExec
Setting up maven: null
Sep 04,2020 3:29:45 PM FINE org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution2 obtainMavenExec
Searching for Maven through MAVEN_HOME and M2_HOME environment variables...
Sep 04,2020 3:29:45 PM FINE org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution2 obtainMavenExec
Calling printenv on docker container...
Sep 04,2020 3:29:45 PM FINE org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution2 obtainMavenExec
NO maven installation discovered on docker container through MAVEN_HOME and M2_HOME environment variables
Sep 04,2020 3:29:45 PM FINE org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution2 obtainMavenExec
Found exec for maven on: null

编辑3:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?