从 Bitbucket 管道中的 Java Maven 项目中获取来自 pom.xml 的版本
Get the version from pom.xml from a Java Maven project in Bitbucket pipeline
有没有办法获取 pom.xml 文件中定义的版本,以便它可以与 Bitbucket 管道中的变量一起使用?
Whosebug 上也有类似的问题,但它们主要指的是 Jenkins 和“readMavenPom”,这在 Bitbucket 管道中似乎不可用。
我想用它作为第二步上传到S3的版本标签
- step:
name: Build and Test
caches:
- maven
script:
- mvn package
artifacts:
- target/myapp-*.jar
- step:
name: Upload to S3
deployment: production
script:
- pipe: atlassian/aws-code-deploy:0.2.10
variables:
AWS_DEFAULT_REGION: $AWS_REGION
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
COMMAND: 'upload'
APPLICATION_NAME: 'myapp'
ZIP_FILE: "target/myapp-*.jar"
S3_BUCKET: 'myapps'
VERSION_LABEL: "myapp-${version}-${BITBUCKET_COMMIT:0:8}"
根据@joe 的提示和类似问题 How to get Maven project version to the bash command line,我可以确认这适用于 Bitbucket 管道:
- step:
name: Get the version from pom.xml
script:
- MVN_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
- echo $MVN_VERSION
结果
+ MVN_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
+ echo $MVN_VERSION
0.0.1-SNAPSHOT
有没有办法获取 pom.xml 文件中定义的版本,以便它可以与 Bitbucket 管道中的变量一起使用?
Whosebug 上也有类似的问题,但它们主要指的是 Jenkins 和“readMavenPom”,这在 Bitbucket 管道中似乎不可用。
我想用它作为第二步上传到S3的版本标签
- step:
name: Build and Test
caches:
- maven
script:
- mvn package
artifacts:
- target/myapp-*.jar
- step:
name: Upload to S3
deployment: production
script:
- pipe: atlassian/aws-code-deploy:0.2.10
variables:
AWS_DEFAULT_REGION: $AWS_REGION
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
COMMAND: 'upload'
APPLICATION_NAME: 'myapp'
ZIP_FILE: "target/myapp-*.jar"
S3_BUCKET: 'myapps'
VERSION_LABEL: "myapp-${version}-${BITBUCKET_COMMIT:0:8}"
根据@joe 的提示和类似问题 How to get Maven project version to the bash command line,我可以确认这适用于 Bitbucket 管道:
- step:
name: Get the version from pom.xml
script:
- MVN_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
- echo $MVN_VERSION
结果
+ MVN_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
+ echo $MVN_VERSION
0.0.1-SNAPSHOT