从Azure管道合并PowerShell中的git分支

从Azure管道合并PowerShell中的git分支,git,azure-pipelines,azure-pipelines-yaml,Git,Azure Pipelines,Azure Pipelines Yaml,我正在Azure管道上工作,运行在Windows自托管代理上 我们有一个yaml管道,可以手动触发、构建项目、创建工件并部署到我们的登台环境 目前它可以工作,它从github获得了开发分支,并按照前面提到的那样做 我想改变这一点,使开发分支合并到发布分支,当版本进入PROD时,我们始终重用相同的发布分支。在未来的步骤中,在批准后,发布分支应合并到主分支。 我不太了解git,我使用SourceSafe很多年了 我不知道哪种方法最好: #一, #二, 第二种方法似乎最好,但随着Azure下载的默认发

我正在Azure管道上工作,运行在Windows自托管代理上

我们有一个yaml管道,可以手动触发、构建项目、创建工件并部署到我们的登台环境

目前它可以工作,它从github获得了开发分支,并按照前面提到的那样做

我想改变这一点,使开发分支合并到发布分支,当版本进入PROD时,我们始终重用相同的发布分支。在未来的步骤中,在批准后,发布分支应合并到主分支。 我不太了解git,我使用SourceSafe很多年了

我不知道哪种方法最好:

#一,

#二,

第二种方法似乎最好,但随着Azure下载的默认发展。。。我想编写一个PowerShell函数来实现这一点,并且可以重用以将发布合并到主版本,最后我编写了这个命令行脚本,但它不起作用:

parameters:
- name: 'SourceBranch'
  default: 'develop'
  type: string
- name: 'TargetBranch'
  default: 'release'
  type: string
- name: 'Tag'
  default: ''
  type: string

- task: CmdLine@2
  inputs:
      script: |
        git checkout ${{parameters.TargetBranch}}
        git tag ${{parameters.Tag}}
        git push --tags

        git pull ${{parameters.SourceBranch}}
我尝试将
SourceBranch
的值更改为
develope
origin\develope
,但我始终得到:

fatal: 'whatever I used' does not appear to be a git repository
我不确定我的代码,如果我的想法是好的,那么如果你能帮我一些指导,那将是非常有帮助的

知道了这一点以后,我将重用源代码为release、目标代码为master的脚本! 谢谢

--更新1----------------------- 以下是管道中默认步骤生成的日志:

##[section]Starting: Checkout [myOrg]/[myProject]@develop to s
git version 2.26.2.windows.1
##[command]git config --get remote.origin.url
##[command]git clean -ffdx
##[command]git reset --hard HEAD
HEAD is now at bd75f7d [***]
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/[myOrg]/[myProject].extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" -c http.proxy="http://[***]:443" fetch --force --tags --prune --progress --no-recurse-submodules origin
##[command]git checkout --progress --force e99a6[***]b4bdf
Note: switching to 'e99a6[***]b4bdf'.
You are in 'detached HEAD' state...
HEAD is now at e99a6ca Update README.md
##[command]git config http.https://github.com/[myOrg]/[myProject].extraheader "AUTHORIZATION: basic ***"
##[command]git config http.proxy "http://[***]:443"
##[section]Finishing: Checkout [myOrg]/[myProject]@develop to s
- name: projectName
  value: '***'

stages:
  - stage: InitRelease
    jobs:
    - job: Branch
      steps:
        - checkout: self
          clean: true
          persistCredentials: true
        - template: git-branch-source-2-target.yml@templates
          parameters:
            TargetBranch: 'release'
            Tag: '${{ variables.projectName }}_${{ variables.buildId }}'
然后,由我的脚本创建的日志:

git checkout release
Previous HEAD position was e99a6ca Update README.md
Switched to branch 'release'
git status
On branch release
nothing to commit, working tree clean
git tag - OECD.Glue.Contacts.API_9457
git push --tags
To https://github.com/[myOrg]/[myProject]
* [new tag]         [myProject]_9457 -> [myProject]_9457
git pull origin\develop
fatal: 'origin\develop' does not appear to be a git repository
fatal: Could not read from remote repository.
我再试了一次,但提供了“仅开发”或“[myOrg]/[myProject]@develope”作为源分支,但我总是得到相同的错误

--更新2-----------------------

默认情况下,管道将签出开发分支,我尝试使用它来防止这种无用的签出:

- checkout: none
但我得到了这个日志:

git status
->  On branch release
->  nothing to commit, working tree clean
git tag ${{parameters.Tag}}
git push --tags
fatal: could not read Username for 'https://github.com': terminal prompts disabled
使用下面的签出,删除了错误,我认为它可以帮助我的问题或任何有此错误的人:

- checkout: self
  clean: true
  persistCredentials: true
-> fatal: The current branch release has no upstream branch.
根据建议,我使用了:

git push
但我有一个错误:

- checkout: self
  clean: true
  persistCredentials: true
-> fatal: The current branch release has no upstream branch.
我试过这个:

git push --verbose --repo=release
然后我得到:

Pushing to release
fatal: 'release' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
这对我来说仍然很模糊,我真的需要先开发吗? 这是否与我们在GitHub中的默认分支始终是“开发”这一事实有关


如何判断我是否有足够的访问权限?在使用相同帐户的GitHub上,我可以比较:“
base:release您走对了方向

您可能希望更新git命令,使其在分支名称之前包含“origin”,并且您可能希望在运行pull之后推送更改,或者这些更改将保持在构建代理的本地阶段

这应该可以做到:

- task: CmdLine@2
  inputs:
      script: |
        git checkout ${{parameters.TargetBranch}}
        git tag ${{parameters.Tag}}
        git push --tags

        git pull origin ${{parameters.SourceBranch}}
        git push

repo在管道中有远程设置吗?我被术语remote,origin弄糊涂了…这是管道的第一个作业,repo被复制到代理,我没有添加任何其他内容。您需要提取日志吗?谢谢。remote是另一个git存储库的术语。它甚至可以在同一台机器上。origin是默认的na我是远程用户。通常这是在复制repo时创建的。如果推/拉操作失败,则管道repo似乎无法连接到其远程用户。我已连接回办公室并从管道中获取日志,我会将它们添加到我编辑的更新1中,感谢您的帮助!嗨,朋友,有关于此票证的更新吗?下面的答案解决了你的问题吗?谢谢@Max Morrow,我觉得我快到了,但还是被阻止了:(我在更新2上写了不同的测试和问题!谢谢。没问题。要解决错误“致命:当前分支版本没有上游分支。",您会想将git push更新为git push--设置上游版本OK,谢谢,但我不明白它的作用以及为什么有必要…您能解释一下吗?我尝试从Github UI创建PR,从开发到发布再到发布,昨天发布到主版本,它工作正常,因此用户帐户确实可以访问!我会尝试布景现在在上游。谢谢。
Switched to branch 'release'
To https://github.com/myOrg/myProject
 * [new tag]         myProject_9527 -> myProject_9527
From https://github.com/myOrg/myProject
 * branch            develop    -> FETCH_HEAD
Already up to date.
Pushing to release
fatal: 'release' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
- task: CmdLine@2
  inputs:
      script: |
        git checkout ${{parameters.TargetBranch}}
        git tag ${{parameters.Tag}}
        git push --tags

        git pull origin ${{parameters.SourceBranch}}
        git push