如何从Azure DevOps Pipeline Dynamics 365 CE添加/更新git存储库中的文件 [英] How to add/update files in git repository from Azure DevOps Pipeline Dynamics 365 CE

查看:113
本文介绍了如何从Azure DevOps Pipeline Dynamics 365 CE添加/更新git存储库中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短版本

触发构建管道时,其中一个构建管道任务将获取最新文件,并且必须在当前运行管道的git存储库中添加/更新该文件.我试图通过使用命令行任务来做到这一点,但是它失败了,因为它不是git仓库

When a build pipeline is triggered, one of the build pipeline task will get the latest files and it has to be added/updated in the git repository of current running pipeline. I tried to do it by using command line task but its failing as not git repository

fatal: not a git repository (or any of the parent directories): .git

长版

我试图为Dynamics 365实例实现解决方案打包和解包过程.因此,构建管道具有以下任务

I m tried to achieve solution pack and unpack process for dynamics 365 instance. So the build pipeline have the following tasks

  1. 从Dynamics 365导出解决方案并将其存储在$(build.binariesdirectory)

  1. Export solution from Dynamics 365 and store it in $(build.binariesdirectory)

解压缩解决方案zip文件并将其存储在$(Build.Repository.LocalPath)中,即添加/更新现有文件

Unpack the solution zip file and store in $(Build.Repository.LocalPath) i.e., adding/updating existing files

命令行任务,用于提交文件并将其推送到当前管道存储库

Command line task to commit and push the files to current pipeline repository

ECHO "Setting git config..."
git config --global user.email "xxx@xyz.com"
git config --global user.name "Admin"

ECHO "CHECK GIT STATUS..."
git status

ECHO "GIT ADD..."
git add -A

ECHO "CHECK GIT STATUS..."
git status

ECHO "Commiting the changes..."
git commit -m "Latest Customizations updated"

ECHO "Pushing the changes..."
git push -u origin master

ECHO "Customization Committed Successfully"

已更新

如果使用2个命令行任务创建管道,即一个在Build.Sourcedirectory中创建一个随机文件,另一个用于提交更改,则git commit和push命令可以正常工作.

If a pipeline is created with 2 command line task i.e. one to create a random file in the Build.Sourcedirectory and another to commit the changes, then the git commit and push commands are working.

但是,如果我们在命令行任务之前添加其他任务(例如,将Build.Sourcedirectory目录中的文件解压缩),则会由于不是存储库而出错.

But if we add other tasks (such as unzip files in Build.Sourcedirectory directory) before the command line task then getting error as not a repository.

如果您看到以下屏幕截图,则在结帐阶段,git repo将被克隆到D:\a\1\s

If you see the below screenshot, in the checkout phase the git repo is cloned to D:\a\1\s

下面的截图来自命令行任务,其中当前工作目录与签出任务相同(即D:\a\1\s),我们可以看到存在".git"文件夹,因此当前目录具有本地存储库在其中,但仍显示错误fatal: not a git repository

And below screenshot is from command line task, where the current working directory is same as the checkout task (i.e., D:\a\1\s) and we can see that the ".git" folder is present so the current directory has local repository in it, but still getting error as fatal: not a git repository

我在这里错过了什么吗?

Am I missing anything here?

推荐答案

默认情况下,将源文件检出到Build.SourcesDirectory(例如,目录:D:\a\1\s),可以将其视为临时git存储库.

By default the source files are checked out to the Build.SourcesDirectory (e.g : Directory: D:\a\1\s), it can be considered as a temporary git repository.

根据错误消息,似乎命令行任务的工作目录不在Build.SourcesDirectory下,并且您没有再次git checkout进入该工作目录.

According to the error message, it appears that the working directory of the command line task is not under the Build.SourcesDirectory and you did't git checkout again to that working directory.

因此,请尝试解压缩解决方案zip文件并将其存储在Build.SourcesDirectory中,然后在命令行下运行以推送提交(对我有用):

So, please try unpack the solution zip file and store in Build.SourcesDirectory, then run below Command line to push the commits (it works for me):

ECHO "Setting git config..."
git config --global user.email "xxx@xyz.com"
git config --global user.name "Admin"

ECHO "CHECK GIT STATUS..."
git status

git checkout -b master

ECHO "GIT ADD..."
git add -A

ECHO "CHECK GIT STATUS..."
git status

ECHO "Commiting the changes..."
git commit -m "Latest Customizations updated"

ECHO "Pushing the changes..."
git push -u origin master

ECHO "Customization Committed Successfully"

请注意,您需要

Please note that you need to Grant version control permissions to the build service and enable Allow scripts to access the system token.

这篇关于如何从Azure DevOps Pipeline Dynamics 365 CE添加/更新git存储库中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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