基于 azure devops yml 的管道中的 git commit 和 git tag [英] git commit and git tag in azure devops yml based pipeline

查看:24
本文介绍了基于 azure devops yml 的管道中的 git commit 和 git tag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种很好的方法来提交更改文件并在基于 azure DevOps yaml 的管道中创建标签?

Is there a nice way to commit the changes file and create a tag in azure DevOps yaml based pipeline?

我的场景是基于 node js 的构建:每次构建时,它都会使用 npm version patch 更改 package.json 版本最后,它会将 package.json 推送到 build 分支(显然条件是 branch==master),并且还会标记并推送一个分支.

My scenario will be for a node js based build: Each build, it will change the package.json version by using npm version patch In the end, It will push the package.json to the build branch (Obviously with condition branch==master) and will tag and push a branch as well.

肮脏的方式可以是:

- bash : |
     git add filename.ext
     git push origin HEAD:branchName
     git tag -a tagName -m 'tag message' 
     git push --tags
  displayName: 'Git Commit and Tag from pipeline'

推荐答案

您可以在 yaml 构建步骤中执行此操作,但重要的部分是您需要管道具有执行推送的权限,最简单的方法是保留结帐时的凭据,如下所示.

You can do this in as yaml build steps, but the important part is that you need the pipeline to have permission to do the push and the simplest way is to keep the credentials from the checkout as below.

然后您需要授予 项目集合构建服务创建标签贡献(添加/删除文件)权限.

You then need to grant the Project Collection Build Service Create tag and Contribute (add/remove files) permissions.

我还发现我必须为推送工作设置工作目录

I also found I had to set the working directory for the push to work

steps:
# Check out the code and keep the token so we can tag the repository
- checkout: self
  persistCredentials: true

--- rest of pipeline

# Tag the current branch with the version number
- script: |
    git add filename.ext
    git push origin
    git tag -a tagName -m 'tag message' 
    git push --tags
  workingDirectory: $(Build.SourcesDirectory)
  displayName: 'Git Commit and Tag from pipeline'

这篇关于基于 azure devops yml 的管道中的 git commit 和 git tag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆