从构建管道推送到本地 Azure DevOps Git [英] Push to local Azure DevOps Git from Build Pipeline

查看:24
本文介绍了从构建管道推送到本地 Azure DevOps Git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

短版

有人能告诉我如何在 Azure DevOps 构建管道中设置命令行脚本"任务,将更改推送到本地 Git 存储库(实际上,管道所基于的 Git 存储库)?

Short version

Can someone tell me how to set up a "Command Line Script" task within an Azure DevOps build pipeline that pushes changes to a local Git repository (in fact, the Git repository on which the pipeline is based)?

无论我尝试什么,我的脚本总是在打印推送提交到 git 后超时.

No matter what I try, my script always times out after printing Pushing commits to git.

更长的版本

我们正在将现有的 Java/Maven 项目从 Jenkins 构建服务器迁移到 Azure DevOps 构建环境,我正在尝试建立一个模仿 Jenkins发布暂存"功能的构建管道.

Longer version

We are migrating existing Java/Maven projects from a Jenkins build server to an Azure DevOps build environment, and I am trying to set up a build pipeline that mimics the Jenkins "Release Staging" functionality.

我的第一次尝试是直接在检出的源上调用 Maven 发布插件.这涉及到几个障碍,其中大部分我都能够以一种或另一种方式克服:

My first attempt was to call the Maven release plugin directly on the checked out sources. This involved several obstacles, most of which I was able to overcome in one way or the other:

  1. 标准的 Azure DevOps git 环境没有设置所需的配置值user.email"和user.name";这可以通过在推送之前在单独的命令行脚本"任务中调用 git config 来解决.
  2. Azure DevOps 在分离的 HEAD 状态"中检查源 - 为了解决这个问题,设置脚本任务还调用 git checkout master.
  1. The standard Azure DevOps git environment doesn't have the required config values "user.email" and "user.name" set; this can be solved by calling git config in a separate "Command Line Script" task prior to pushing.
  2. Azure DevOps checks out the sources in a "detached HEAD state" - to solve this problem, the setup script tasks also calls git checkout master.

一旦设置完成,我的 Maven 调用脚本就会运行到发布插件尝试推送到 Git 的位置;读取日志文件中的相应行

Once this is set up, my Maven call script runs up to the point where the release plugin attempts to push to Git; the corresponding lines in the log file read

[INFO] Executing: cmd.exe /X /C "git push https://xxx.visualstudio.com/YYY/_git/zzz refs/heads/master:refs/heads/master"
[INFO] Working directory: D:a1s</code>

在那之后,在超时到来之前,什么都不会发生(至少,什么都不会被记录):

After that, nothing happens (at least, nothing gets logged) until the timeout strikes:

##[error]The operation was canceled.
##[section]Finishing: Maven pom.xml

为了找出导致此问题的原因,我尝试了一些方法,其中包括

In order to find out what causes this problem I tried a few things, among others,

  • 禁用maven调用并直接从脚本调用git push
  • 注册一个store"类型的Git凭证助手(假设是认证问题导致超时),

但没有成功.我现在想不出如何让 git push 调用工作的想法 - 有没有人可以帮助我?

but without success. I am now running out of ideas how I could get the git push call to work - is there anyone out here who can help me out?

P.S.:如您所知,就 Azure DevOps 而言,我是一个新手,所以我肯定不了解该系统的所有技巧和功能.特别是,我不知道是否有任何提供与 Maven 发布插件相同的功能.我们确实使用了 Azure DevOps 包管理,但我们希望为快照和发布版本保留单独的提要(就像 Nexus 这样的工具所做的那样),因此我们必须有一种机制来自动推进发布编号、检出和返回以及构建打包模块并将其发布到发布提要.

P.S.: As you may be able to tell, I'm rather a newbie as far as Azure DevOps is concerned, so I surely don't know all tricks and features of that system. In particular, I don't know if there is anything that offers the same functionality as the Maven release plugin. We do use the Azure DevOps package management, but we want to keep separate feeds for snapshots and for release builds (the way tools like Nexus do), so we have to have a mechanism for automatically advancing release numbers, checking out and back in and building and publishing the packaged module to the release feed.

如果有人可以提出替代方法来实现这一目标,我也愿意接受建议.

If someone can suggest an alternative way to achieve that, I'm open to suggestions as well.

推荐答案

要将更改推送到 Azure DevOps,您应该在 Git 存储库 URL 中集成您的凭据:

To push change to Azure DevOps, you should integrate your credential in Git repo URL:

  • 首先,创建一个 PAT 如果你没有.
  • 然后使用下面的命令推送:

  • First, create a PAT if you not have.
  • Then use below command to push:

git push https://Personal%20Access%20Token:PAT@xxx.visualstudio.com/YYY/_git/zzz master

这篇关于从构建管道推送到本地 Azure DevOps Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆