在Azure DevOps Git rep中使用来自Azure管道的Python包版本标记Git repo

2024-09-26 18:06:20 发布

您现在位置:Python中文网/ 问答频道 /正文

上下文

我们将azuredevops用于Git回购,将azurepipelines用于CI/CD,将azureartifacts用于私有托管python包。你知道吗

目标

我想:

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管道变量作为内部版本号。你知道吗

在构建管道上,有一个复选框,用于在成功构建轮子工件时标记回购。你知道吗

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

但我不确定如何将包版本作为管道变量公开,因为这个作业没有位置让我转义以执行自定义代码。我肯定有办法做到这一点,但我在这一点上,我需要帮助和文件是没有指导我到正确的地方,根据我的查询和阅读。你知道吗


Tags: pygitci目标管道versiontagwith
1条回答
网友
1楼 · 发布于 2024-09-26 18:06:20

不满意这种方法,但它实现了结果。你知道吗

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

参考文献:

相关问题 更多 >

    热门问题