作为构建过程的一部分,我们更新版本号,并且希望提交更改并将其推送回主存储库。这是托管在 azure devops 上的 git 存储库,第一步使用获取源:
我使用以下代码在管道末尾添加了一个命令行任务。似乎有什么问题,我该如何正确地做到这一点?谢谢。
git config --global user.email "my@email.address.com"
git config --global user.name "VSTS Admin"
git status
ECHO SOURCE BRANCH IS %BUILD_SOURCEBRANCH%
ECHO ADDING MODIFIED FILES
git add *.cs
git add *.build
git add *.wxs
ECHO CREATING COMMIT
git commit -m "Update version numbers for Build %BUILD_BUILDNUMBER%"
git push origin master
Run Code Online (Sandbox Code Playgroud)
结果如下:
##[section]Starting: Commit/Push Changes To Git Repo
==============================================================================
Task : Command Line
Description : Run a command line script using cmd.exe on Windows and bash on macOS and Linux.
Version : 2.148.0
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
==============================================================================
Generating script.
========================== Starting Command Output ===========================
##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\8b19361b-8f47-4d31-834d-132fedb0b386.cmd""
HEAD detached at e7a1479d
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: ../../../Properties/AssemblyInfo.cs
.. (more files modified)
SOURCE BRANCH IS refs/heads/master
ADDING MODIFIED FILES
CREATING COMMIT
[detached HEAD 5c1bf6dc] Update version numbers for Build myBuildNumber_5.1.001
2 files changed, 2 insertions(+), 2 deletions(-)
error: src refspec master does not match any
error: failed to push some refs to 'https://{org}@dev.azure.com/{projectName}/_git/{reponame}'
##[error]Cmd.exe exited with code '1'.
##[section]Finishing: Commit/Push Changes To Git Repo
Run Code Online (Sandbox Code Playgroud)
需要注意的事项是:
git checkout <commit-hash-SHA1>git push <remote-repo-url> HEAD:refs/heads/<target-branch> 可以是 原始或完全限定的repo-urlgit push url_with_pat HEAD:refs/heads/<target-branch>(url 还可以包含 PAT(Github 的个人访问令牌 - 具有对目标存储库的写访问权限)的格式:https://<username>:<PAT>@github.com/<username>/<repo>.gitenvironment variable $(Build.SourceBranch)它,format /refs/head/<branch>因为它处于分离状态模式(uses refs-heads)如果出于某种原因您试图不结账分支,这尤其有用
如果不需要上述方法,那么仍然可以使用经典的方式直接检查特定分支git checkout -b <branch>
注意:可以用修剪过的 $(Build.SourceBranch) 替换,其中/refs/heads/可以在使用之前删除前缀
| 归档时间: |
|
| 查看次数: |
7776 次 |
| 最近记录: |