有没有办法以编程方式在 jenkinsfile 中指定 pom.xml 路径
Is there a way to programmatically specify pom.xml path in jenkinsfile
在声明性管道中,我在 Jenkinsfile 中手动指定 pom.xml 路径,Jenkins 能够在构建时按预期找到它。
pipeline {
agent any
options {
timestamps()
}
stages {
stage('Compile') {
steps {
withMaven(maven: 'MAVEN_HOME') {
sh 'mvn -f /Users/jo/.jenkins/workspace/DeclarativePipelineDemo/Demo/pom.xml clean install' //filepath
}
}
}
}
现在,有没有更优雅的方式让 Jenkins 直接从我的项目中动态捕获 workspace/pom.xml
类路径,这样我就不需要手动指定它了?
如果你的 Jenkinsfile 在 pom.xml 的同一个 repo 中,你可以使用相对路径。
当 Jenkins 运行 管道时,它会自动将保存 Jenkinsfile 的 repo 克隆到 Jenkins slave。
如果pom.xml在项目的基础目录中,你可以试试
sh mvn -f pom.xml ...
在声明性管道中,我在 Jenkinsfile 中手动指定 pom.xml 路径,Jenkins 能够在构建时按预期找到它。
pipeline {
agent any
options {
timestamps()
}
stages {
stage('Compile') {
steps {
withMaven(maven: 'MAVEN_HOME') {
sh 'mvn -f /Users/jo/.jenkins/workspace/DeclarativePipelineDemo/Demo/pom.xml clean install' //filepath
}
}
}
}
现在,有没有更优雅的方式让 Jenkins 直接从我的项目中动态捕获 workspace/pom.xml
类路径,这样我就不需要手动指定它了?
如果你的 Jenkinsfile 在 pom.xml 的同一个 repo 中,你可以使用相对路径。
当 Jenkins 运行 管道时,它会自动将保存 Jenkinsfile 的 repo 克隆到 Jenkins slave。
如果pom.xml在项目的基础目录中,你可以试试
sh mvn -f pom.xml ...