上下文
我们使用 Azure DevOps 进行 Git Repos,使用 Azure Pipelines 进行 CI/CD,使用 Azure Artifacts 进行 Python 包的私有(private)托管。
目标
我想要:
Tag a Git repo with Python Package version from Azure Pipelines in Azure DevOps Git repo
示例
git tag -a "$(python setup.py --version)" -m "Released version $(python setup.py --version)"
我已阅读 Azure 文档,但似乎它们都使用 Azure Pipeline 变量作为内部版本号。
在构建管道上,有一个复选框可以在成功构建轮工件时标记存储库。
但我不确定如何将包版本公开为管道变量,因为这项工作没有地方让我逃避执行自定义代码。我确信有一种方法可以做到这一点,但我现在需要帮助,并且文档没有根据我正在查询和阅读的内容指导我到正确的位置。
最佳答案
对这种方法不满意,但它实现了结果。
感谢 @C.Nivs 提出的建议,即在成功构建的轮子和导出构建工件的任务之间破解 Bash 脚本。
# Get Package Version
export PACKAGE_VERSION="$(python setup.py --version)"
echo "Package Version: v${PACKAGE_VERSION}"
# Get the body of the last merge commit message
git log HEAD~1..HEAD --format="RELEASE:v${PACKAGE_VERSION} Notes:%s%n%b"
export TAG_MESSAGE=$(git log HEAD~1..HEAD --format="RELEASE:v${PACKAGE_VERSION} Notes:%s%n%b")
echo $TAG_MESSAGE
# Set the config for the CI to be able to commit a tag
git config --global user.email "ci-pipeline@myorganisation.com"
git config --global user.name "Azure Pipelines: python-wheel-artifact"
# Create the tag locally as an annotated tag
# https://stackoverflow.com/questions/11514075/what-is-the-difference-between-an-annotated-and-unannotated-tag
git tag -a "v$PACKAGE_VERSION" -m "$TAG_MESSAGE"
# Update the push remote as the Personal Access Token URL
# Inject these values from the Pipeline variables.
git remote set-url --push origin "https://$(tag_push_username):$(tag_push_personal_access_token)@dev.azure.com/<myorganization>/<myproject>/_git/<myreponame>"
# Ensure the source of truth receives the tag.
git push --tags
引用文献:
关于python - 在 Azure DevOps Git 存储库中使用来自 Azure Pipelines 的 Python 包版本标记 Git 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59399368/