在我的 android 项目的 POM.xml 文件中,我创建了六个配置文件。我从命令行运行这些,例如 mvn clean install -P mdpi。这工作正常。现在我将 jenkins 用于我的 CI。我希望向用户显示所有配置文件的下拉列表,然后使用mvn clean install -P ${selected-profile}
该${selected-profile}
变量包含构建的配置文件。我怎样才能做到这一点?
问问题
23734 次
2 回答
0
我已将以下内容添加到我的 Jenkins 文件中:
pipeline {
agent {
label 'common'
}
tools {
maven 'Maven-3.5.4'
}
stages {
stage('Build and Publish') {
when {
anyOf {
buildingTag();
branch 'master';
branch 'develop';
branch 'release/**';
}
}
steps {
script {
def server = Artifactory.server 'test-artifactory'
def rtMaven = Artifactory.newMavenBuild()
def buildInfo
//Set defualt profile
def mvnProfile = 'dev'
//Set the target mvn profile based on the current branch
if(env.BRANCH_NAME.equals('master')){
mvnProfile = 'prod'
}else if(env.BRANCH_NAME.startsWith('release/')){
mvnProfile = 'test'
}
rtMaven.tool = "Maven-3.5.4"
// Set Artifactory repositories for dependencies resolution and artifacts deployment.
rtMaven.deployer releaseRepo:'libs-release-local', snapshotRepo:'libs-snapshot-local', server: server
buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean install -Dmaven.test.skip=true -P' + mvnProfile
server.publishBuildInfo buildInfo
}
}
}
}
}
我在脚本中添加了以下条件 if 来设置目标 mvn 配置文件:
//Set defualt profile
def mvnProfile = 'dev'
//Set the target mvn profile based on the current branch
if(env.BRANCH_NAME.equals('master')){
mvnProfile = 'prod'
}else if(env.BRANCH_NAME.startsWith('release/')){
mvnProfile = 'test'
}
于 2020-05-06T12:45:56.447 回答