Jenkins 管道:合并失败

罗伯特·艾克兰

我目前正在设置我的管道,以便在将任何更改提交到分支时,如果构建和测试通过,它将与 master 合并。但是,我收到此错误:

[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前端”,所以它似乎是我无法摆脱的更改。硬重置不会删除它。

通过添加EDIT 2git clean -ffd,frontend/ 文件夹现在消失了,但构建仍然失败。

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

    }
}
萨吉布汗

您有本地未合并的更改。所以,在合并之前做提交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"
    }
}

注意:确保您具有远程master分支的推送或写入权限

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章