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

查看:352
本文介绍了从构建管道推送到本地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)?

无论我尝试什么,我的脚本在打印 Pushing commits to 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:\a\1\s</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
  • 注册商店"类型的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天全站免登陆