python - 在 Azure DevOps Git 存储库中使用来自 Azure Pipelines 的 Python 包版本标记 Git 存储库

标签 python git azure-devops azure-pipelines

上下文

我们使用 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 变量作为内部版本号。

在构建管道上,有一个复选框可以在成功构建轮工件时标记存储库。

Image of 'Get Sources Job' option to tag a release on success

但我不确定如何将包版本公开为管道变量,因为这项工作没有地方让我逃避执行自定义代码。我确信有一种方法可以做到这一点,但我现在需要帮助,并且文档没有根据我正在查询和阅读的内容指导我到正确的位置。

最佳答案

对这种方法不满意,但它实现了结果。

感谢 @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/

相关文章:

Python 多重赋值和引用

git - 如何将本地 git repo 与 origin/master 同步以消除所有更改

git - 为什么 git 将 unicode 显示为二进制?

azure-devops - 如何在本地将工作项从 VSTS 迁移到 TFS 2015?

Azure DevOps管道: read parameter values from a yaml and formulate a checklist

python - 将列表中的所有元素打印到另一个字符串旁边

python - sklearn中VotingClassifier的继承

node.js - 如何让我的 Next.js 应用程序在运行 ubuntu-latest 的 Azure 应用服务中启动?

python - 为什么 tkinter ttk 在 python 3.5.1 中显示 "name ttk is not defined"

git - 如何 `git fetch`默认分支