【发布时间】:2017-11-30 11:05:59
【问题描述】:
我目前正在设置我的管道,以便当任何更改提交到分支时,如果构建和测试通过,它将与主分支合并。但是,我收到此错误:
[Build, test and deploy front] Running shell script
+ git merge origin/Develop
error: merge is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
消息很清楚,由于合并冲突,它不会合并。但是,我尝试合并到 master 的分支是从 master 创建的新分支 - 所以目前没有任何更改。我不知道它指的是什么冲突。
这是我的管道:
pipeline {
agent any
// this tool will be used for all stages/steps except over-written
tools {nodejs "newest node"}
stages {
stage('build') {
steps {
sh 'cd frontend'
sh 'npm install'
}
}
stage('test'){
steps{
echo 'Hello, JDK'
}
}
stage('update master'){
steps{
sh 'git merge origin/Develop'
sh 'git commit -am "Merged develop branch to master'
sh "git push origin master"
}
}
}
}
编辑:
这是我现在使用的代码
pipeline {
agent any
// this tool will be used for all stages/steps except over-written
tools {nodejs "newest node"}
stages {
stage('build') {
steps {
sh 'cd client'
sh 'npm install'
}
}
stage('update master'){
steps{
sh 'git add -A'
sh 'git reset --hard HEAD'
sh 'git merge origin/Develop'
sh 'git commit -m "Merged develop branch to master"'
sh "git push origin master"
}
}
}
}
这会返回错误:
HEAD detached from 25e2038
Untracked files:
frontend/
nothing added to commit but untracked files present
所以现在合并似乎成功了,但提交不会通过并在未跟踪的文件上引发错误。我的 github 文件夹中不存在前端,但我之前的代码确实是“cd frontend”,所以这似乎是一个我无法摆脱的变化。硬重置不会删除它。
编辑 2
通过添加git clean -ffd,frontend/ 文件夹现在消失了,但构建仍然失败。
回答 这是我想做的代码的工作版本:
pipeline {
agent any
// this tool will be used for all stages/steps except over-written
tools {nodejs "newest node"}
stages {
stage('build') {
steps {
sh 'npm install'
}
}
stage('update master'){
steps{
sh 'git add -A'
sh 'git commit --allow-empty -am "Merged developer branch into master"'
sh 'git merge origin/Develop'
sh "git push origin HEAD:master"
}
}
}
}
【问题讨论】:
标签: git jenkins merge jenkins-pipeline