当前位置: 首页 > news >正文

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 设置变量

http://www.lryc.cn/news/485239.html

相关文章:

  • LeetCode74. 搜索二维矩阵(2024冬季每日一题 6)
  • BPMN 2.0详细介绍
  • web——upload-labs——第四关——.htaccess文件绕过
  • 36.矩阵格式的等差数列 C语言
  • Java 语言的强大特性
  • ElementUI的日期组件中禁止选择小时、分钟、秒
  • 4.2 Android NDK 基础概念
  • PIL包在Python图像处理中的应用
  • ArcGIS Pro ADCore DAML
  • Clip结合Faiss+Flask简易版文搜图服务
  • 【机器学习】数学知识:欧式距离(Euclidean Distance)和曼哈顿距离(Manhattan Distance)
  • Redis 概 述 和 安 装
  • 数据仓库面试题集离线实时
  • Spring Boot框架:电商系统的技术革新
  • 一键抠图:免费安全的在线图片去除背景工具
  • vue项目PC端和移动端实现在线预览pptx文件
  • uniapp适配暗黑模式配置plus.nativeUI.setUIStyle适配DarkMode配置
  • EXCEL 或 WPS 列下划线转驼峰
  • 走进Linux的历史发展史
  • 学习yum工具,进行安装软件
  • union介绍及使用
  • 安全,服务器证书和SSL连接
  • Java结合ElasticSearch根据查询关键字,高亮显示全文数据。
  • Design Compiler:Topographical Workshop Lab2
  • 【C语言】连接陷阱探秘(1):声明与定义
  • ChatGPT学术专用版,一键润色纠错+中英互译+批量翻译PDF
  • python isinstance(True, int)
  • 1.5寸**进口 128128带灰阶oled屏 spi串口 老王电子diy 设备 OLED 2024/11/15 arduino
  • 【EasyExcel】复杂导出操作-自定义颜色样式等(版本3.1.x)
  • 机器学习 ---线性回归