欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > Azure pipeline 通过git命令修改文件

Azure pipeline 通过git命令修改文件

2025/2/24 8:55:10 来源:https://blog.csdn.net/april_4/article/details/143799089  浏览:    关键词:Azure pipeline 通过git命令修改文件

步骤及解释

设置git用户名

git config --global user.email "useremail"
git config --global user.name "username"

获取branch

$branch = "$(Build.SourceBranch)" -replace "refs/heads/"

"$(Build.SourceBranch)":这是一个环境变量,它包含了触发当前构建的分支的完整引用路径。例如,如果构建是由 main 分支触发的,那么这个变量的值可能是 refs/heads/main

-replace "refs/heads/":这是PowerShell中的一个操作符,用于替换字符串中的指定模式。在这里,它用于从 $(Build.SourceBranch) 的值中移除 refs/heads/ 部分,只留下分支的名称。

示例

假设 $(Build.SourceBranch) 的值是 refs/heads/feature/new-feature,那么执行这行命令后:

  • 原始值refs/heads/feature/new-feature
  • 处理后的值feature/new-feature

修改并push

git checkout -b $branchWrite-Host "Adding changes to staging area..."
git -C "$(Build.SourcesDirectory)" add **/package.json
Write-Host "Committing changes..."
git -C "$(Build.SourcesDirectory)" commit -m "your change"
Write-Host "Pushing changes to remote repository..."
git -C "$(Build.SourcesDirectory)" -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push --set-upstream origin $branch 
Write-Host "Done."

整体

- powershell: |git config --global user.email "email"git config --global user.name "name"$branch = "$(Build.SourceBranch)" -replace "refs/heads/"Write-Host "this is the $branch"git checkout -b $branchWrite-Host "Adding changes to staging area..."git -C "$(Build.SourcesDirectory)" add **/package.jsonWrite-Host "Committing changes..."git -C "$(Build.SourcesDirectory)" commit -m "your changes"Write-Host "Pushing changes to remote repository..."git -C "$(Build.SourcesDirectory)" -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push --set-upstream origin $branchWrite-Host "Done."workingDirectory: "$(Build.SourcesDirectory)"failOnStderr: falsedisplayName: "Update Version number to Repo"

git -C 在某路径下执行

git -c 设置变量

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com