问题描述
短版
当触发构建管道时,构建管道任务之一将获取最新文件,并且必须在当前运行管道的 git 存储库中添加/更新它.我试图通过使用命令行任务来做到这一点,但由于不是 git 存储库而失败
fatal:不是 git 存储库(或任何父目录):.git
长版
我试图实现动态 365 实例的解决方案打包和解包过程.所以构建管道有以下任务
从 Dynamics 365 导出解决方案并将其存储在 $(build.binariesdirectory)
解压解决方案 zip 文件并存储在 $(Build.Repository.LocalPath) 中,即添加/更新现有文件
提交文件并将文件推送到当前管道存储库的命令行任务
ECHO "设置 git 配置..."git config --global user.email "[email protected]"git config --global user.name "管理员"ECHO "检查 GIT 状态..."状态ECHO "GIT 添加..."git add -AECHO "检查 GIT 状态..."状态ECHO提交更改..."git commit -m "最新的自定义更新"ECHO 推动改变……"git push -u 原点大师ECHO定制成功"
更新
如果使用 2 个命令行任务创建管道,即一个在 Build.Sourcedirectory
中创建一个随机文件,另一个用于提交更改,则 git commit 和 push 命令正在工作.
但是如果我们在命令行任务之前添加其他任务(例如在 Build.Sourcedirectory
目录中解压缩文件),则会出现错误,因为不是存储库.
如果你看到下面的截图,在结账阶段,git repo 被克隆到 D:a1s
下面的截图来自命令行任务,当前工作目录与结帐任务相同(即D:a1s
),我们可以看到.git"文件夹存在,所以当前目录中有本地存储库,但仍然收到错误 fatal: not a git repository
我在这里遗漏了什么吗?
默认情况下,源文件被检出到 Build.SourcesDirectory
(例如:目录:D:a1s
),它可以被认为是一个临时的 git 存储库.
根据错误提示,命令行任务的工作目录似乎不在Build.SourcesDirectory
下,你没有再次git checkout
那个工作目录.
因此,请尝试解压解决方案 zip 文件并存储在 Build.SourcesDirectory
中,然后在命令行下运行以推送提交(它对我有用):
ECHO "设置 git 配置..."git config --global user.email "[email protected]"git config --global user.name "管理员"ECHO "检查 GIT 状态..."状态git checkout -b masterECHO "GIT 添加..."git add -AECHO "检查 GIT 状态..."状态ECHO提交更改..."git commit -m "最新的自定义更新"ECHO 推动改变……"git push -u 原点大师ECHO定制成功"
请注意,您需要
Short Version
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
Long Version
I m tried to achieve solution pack and unpack process for dynamics 365 instance. So the build pipeline have the following tasks
Export solution from Dynamics 365 and store it in $(build.binariesdirectory)
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 "[email protected]"
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"
Updated
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.
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.
If you see the below screenshot, in the checkout phase the git repo is cloned to D:a1s
And below screenshot is from command line task, where the current working directory is same as the checkout task (i.e., D:a1s
) 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?
By default the source files are checked out to the Build.SourcesDirectory
(e.g : Directory: D:a1s
), it can be considered as a temporary git repository.
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.
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 "[email protected]"
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 存储库中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!