简体   繁体   English

在 Azure DevOps 中拉取请求后挂钩或修改文件的任务

[英]Hook oder Task to modify files after pull request in Azure DevOps

I would like to modify some files in my protected master-branch after a pull-request from a feature-branch to the master-branch is done in Azure DevOps Server.在 Azure DevOps 服务器中完成从功能分支到主分支的拉取请求后,我想修改受保护的主分支中的一些文件。

One file needs to be renamed, another file needs to be created and a in a third file there is a string to replace.一个文件需要重命名,另一个文件需要创建,并且在第三个文件中有一个字符串要替换。

Is this possible through server side git hooks or an Azure Pipeline or Task (sorry, I´m new to this topic).这是否可以通过服务器端 git 钩子或 Azure 管道或任务(对不起,我是这个主题的新手)。

Update更新

The hook or pipeline should do following:钩子或管道应执行以下操作:

  1. check if a file current.sql has any content (if yes, go to next step)检查文件 current.sql 是否有任何内容(如果有,转到下一步)
  2. update an integer-variable (DbVersion) in a C#-Class (add 1 to it)更新 C# 类中的整数变量 (DbVersion)(向其添加 1)
  3. rename the current.sql file to db_update_[new DbVersion].sql将 current.sql 文件重命名为 db_update_[new DbVersion].sql
  4. create a new empty current.sql file创建一个新的空 current.sql 文件

Your scenario description is a bit vague, but I will try to write some answer based on what I understand you want to do:你的场景描述有点模糊,但我会尝试根据我理解你想要做的来写一些答案:

Generally, it is not good practice to modify your branch in your build pipeline.通常,在构建管道中修改分支不是一个好习惯。 As mentioned before, you should do that before merging the pull request in to your branch.如前所述,您应该在将拉取请求合并到您的分支之前执行此操作。

For what you describe it might be good to know, that Git handles versioning automatically.对于您所描述的内容,最好知道 Git 会自动处理版本控制。 Each commit creates a new version of the changed file, which you can find in the commit history in Azure DevOps.每次提交都会创建更改文件的新版本,您可以在 Azure DevOps 的提交历史记录中找到该版本。 It sounds to me as if you basically just don't want to loose the edits you made in your .sql file.在我看来,您基本上只是不想丢失您在 .sql 文件中所做的编辑。

If you, though, require the new version of the file to be part of the build artifact which your pipeline creates, it might make sense to write a short shell script, which you can run via a shell script task .但是,如果您需要新版本的文件成为管道创建的构建工件的一部分,那么编写一个简短的 shell 脚本可能是有意义的,您可以通过shell script task运行该脚本 For string replacement, use the "Replace token" task .对于字符串替换,请使用“替换令牌”任务

Another solution might be a pre-push githook, which would execute a shell script creating the new file?另一个解决方案可能是 pre-push githook,它会执行创建新文件的 shell 脚本? You can read more about githooks here .您可以在此处阅读有关 githooks 的更多信息。

I hope you found something useful in this, otherwise it would be good to know what you want to do with the versions that you create.我希望你在这方面找到了一些有用的东西,否则最好知道你想用你创建的版本做什么。 Are you going to use the versions lateron?你以后会使用这些版本吗? Maybe it might be better to reconsider a different branching model, which supports multiple environments.也许重新考虑支持多种环境的不同分支模型可能会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM