Jenkins管道:合并失败

时间:2017-11-30 11:05:59

标签: git jenkins merge jenkins-pipeline

我正在设置我的管道,以便当任何更改提交到分支时,如果构建和测试通过,它将与主服务器合并。但是,我收到了这个错误:

[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,前端/文件夹现在已经消失,但构建仍然失败。

ANSWER 这是我想要执行的代码的工作版本:

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"
            }
    }

    }
}

1 个答案:

答案 0 :(得分:1)

您有本地未更改的更改。所以,在合并origin/Develop之前进行提交。

    stage('update master'){
    steps{
       sh 'git add -A'
       sh 'git commit -m "Merged develop branch to master'
       sh 'git merge origin/Develop'
       sh 'git push origin HEAD:master'
    }
}

或者,如果更改对于提交不重要,请执行hard reset

stage('update master'){
    steps{
        sh 'git add -A'
        sh 'git reset --hard HEAD'
        sh 'git merge origin/Develop'
        sh 'git clean -ffd'
        sh "git push origin HEAD:master"
    }
}

N.B:确保您拥有远程master分支的推送或写入权限。