如何解决如何在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 举报,一经查实,本站将立刻删除。