简体   繁体   English

如何将最新提交推送到 devops 构建管道的外部远程源?

[英]How can I push latest commits to external remote origin a devops build pipeline?

I have 2 separate code repos containing the same code, origin 1 and origin 2. Our development team only pushes new code to origin 1, but I need to build our code from origin 2.我有 2 个单独的代码仓库,包含相同的代码,源 1 和源 2。我们的开发团队只将新代码推送到源 1,但我需要从源 2 构建我们的代码。

How can I keep the two origin remotes up to date automatically using Azure Devops CI?如何使用 Azure Devops CI 自动使两个源遥控器保持最新?

My thought is to use a Azure Devops Build Pipeline connected to Origin 1 and in the build add Origin 2 as a remote, and then push the changes, but the devops pipeline seems to detach the head when cloning the latest changes.我的想法是使用连接到 Origin 1 的 Azure Devops Build Pipeline 并在构建中添加 Origin 2 作为远程,然后推送更改,但是在克隆最新更改时,devops 管道似乎分离了头部。

Any idea how to automate this?知道如何自动化吗?

Right now I have:现在我有:

- task: CmdLine@2
  inputs:
    script: |
      echo Adding git remote
      git remote add origin2 https://myRemoteoriginGit
      git push origin2 my-branch
    failOnStderr: true

Any idea how to automate this?知道如何自动化吗?

In Origin 1 pipeline, you could try the following script in PowerShell Task.在 Origin 1 管道中,您可以在PowerShell任务中尝试以下脚本。

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      $branch="$(Build.SourceBranch)".replace("refs/heads/","")
      git remote add Reponame https://PAT@dev.azure.com/org/project/_git/reponame
      git checkout $branch
      git push Reponame $branch -f

You could set All branches to trigger this build ( CI triggers ).您可以设置所有分支来触发此构建( CI 触发器)。

Then this script will update the changes to the corresponding branch in Origin 2.然后此脚本将更新对 Origin 2 中相应分支的更改。

The devops pipeline seems to detach the head when cloning the latest changes.克隆最新更改时,devops 管道似乎分离了头部。

According to your description, i guess what you see is this text:根据你的描述,我猜你看到的是这样的文字:

You are in 'detached HEAD' state.您处于“分离的 HEAD”state 中。 You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by switching back to a branch.您可以环顾四周,进行实验性更改并提交它们,您可以放弃在此 state 中所做的任何提交,而不会通过切换回分支来影响任何分支。

If yes, this is how Azure DevOps works.如果是,这就是 Azure DevOps 的工作方式。 Nothing is wrong.没有什么是错的。

Here is a ticket , you could refer to it.这是一张票,你可以参考一下。

Hope this helps.希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有先前的提交的情况下将特定提交推送到远程? - How can I push specific commit to a remote, without the previous commits? 如何将特定提交推送到远程,而不是以前的提交? - How can I push a specific commit to a remote, and not previous commits? 如何将当前状态和所有以后的提交推送到另一个远程服务器,而又不推送所有以前的提交? - How can I push the current state and all later commits to another remote, without pushing all the previous commits? 本地比远程源主机提前 5 次提交,我如何查看将上传的内容? - Local is 5 commits ahead of remote origin master, how can I see what will be uploaded? 如何使用某些提交创建标签并将其推送到源? - How do I create tag with certain commits and push it to origin? 我该如何从“原始”远程站点拉出每个分支并推送到“备份”远程站点 - How can I pull every branch from “origin” remote and push to our “backup” remote 如何在Azure DevOps中创建使用外部git存储库和个人身份验证令牌的管道 - How can I create a pipeline in Azure DevOps that uses an external git repo and a personal authentication token 我无法将分支推送到<remote> ,以及必要的提交和对象</remote> - I can`t Push the branch to <remote> , along with necessary commits and objects 如何合并提交并推送到远程 - how to combine commits and push to the remote 如何排除对管道 yaml 文件的更改以触发构建 i azure devops? - How can I exclude changes to the pipeline yaml file to trigger a build i azure devops?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM