【问题标题】:Git on Azure self hosted agent pipelinesAzure 自托管代理管道上的 Git
【发布时间】:2021-04-08 23:26:07
【问题描述】:

我正在为 GitHub 网站构建 Azure 管道,以便在 Windows 自托管代理上运行。 GitHub 项目的默认分支是develop,所有开发者都提交到这个分支。我想要一个脚本,该脚本将在测试版本时合并开发以发布,并在生产中合并发布以掌握一次。

我是 git 命令的新手,我知道管道在代理上的服务帐户下运行,在代理后面,并且管道以某种方式模拟到另一个帐户以连接到 GitHub。

为了测试我的脚本,我以服务帐户登录服务器并运行以下命令:

REM At start, the pipeline is on the develop branch so I move to release branch
C:\Agent\_work\29\s> git checkout release
>Updating files: 100% (928/928), done.
>Previous HEAD position was a62***: *comment*
>Switched to a new branch 'release'
>Branch 'release' set up to track remote branch 'release' from 'origin'.

C:\Agent\_work\29\s>git tag "branchTests"

C:\Agent\_work\29\s>git status
>On branch release
>Your branch is up to date with 'origin/release'.
>
>nothing to commit, working tree clean

REM I understood I had to first get the release branch and then pull the develop branch over it before pushing it all back
C:\Agent\_work\29\s>git pull origin develop
fatal: could not read Username for 'https://github.com': No such file or directory

C:\Agent\_work\29\s>git push --verbose --repo=release --set-upstream 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.

我有两个问题:

  1. 我的脚本在这种情况下是否正确?
  2. 这个用户名错误是否来自我使用服务帐户?我应该以某种方式冒充管道所做的同一帐户吗?

谢谢。

##########更新1

我注意到如果我不禁用管道中的结帐,我不需要添加它

git config --global user.email "you@example.com"
git config --global user.name "xxx"
git remote set-url origin https://user:{GitHubPAT}@github.com/xxx/xxx.git

我有两个文件:

stages:
  - stage: InitRelease
    jobs:
    - job: Branch
      steps:
        - checkout: self
          clean: true
          persistCredentials: true
        - template: git-branch-source-2-target.yml@templates
          parameters:
            Tag: '${{ variables.projectName }}_${{ variables.buildId }}'

git-branch-source-2-target.yml

parameters:
- name: 'SourceBranch'
  default: 'develop'
  type: string

- name: 'TargetBranch'
  default: 'release'
  type: string

- name: 'Tag'
  default: ''
  type: string

steps:
- task: CmdLine@2
  enabled: true
  displayName: 'GIT Release'
  inputs:
      script: |
        git checkout ${{parameters.SourceBranch}}
        git pull origin 

        git checkout ${{parameters.TargetBranch}}
        git pull origin 

        git tag ${{parameters.Tag}}
        git push --tags

        git merge ${{parameters.SourceBranch}} 
        git push origin --all --verbose

谢谢!

【问题讨论】:

    标签: github azure-pipelines


    【解决方案1】:

    在管道的cmd任务中运行如下命令:

    git config --global user.email "you@example.com"
    git config --global user.name "xxx"
    
    git remote set-url origin https://user:{GitHubPAT}@github.com/xxx/xxx.git
    git checkout develop
    git pull origin
    git checkout release
    git merge develop
    git push origin --all
    

    【讨论】:

    • 成功了!不过,我添加了一个额外的“拉”,非常感谢!我将在更新 1 中解释
    猜你喜欢
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 2021-11-14
    • 1970-01-01
    • 2020-01-01
    • 2021-02-20
    • 1970-01-01
    相关资源
    最近更新 更多