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

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

问题描述

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

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

我的场景是基于节点js的构建:每次构建时,它将使用 npm version patch 更改package.json版本最后,它将把package.json推送到build分支(显然带有condition 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标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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