通过jenkins管道成功构建后无法将pr合并到master

问题描述 投票:1回答:2
sh 'git config --global user.name "$ghprbTriggerAuthor"'  
    sh 'git config --global user.email "$ghprbTriggerAuthorEmail"'  
    checkout changelog: true, poll: true, scm:
      [$class                           : 'GitSCM',
       branches                         : [[name: sha1]],
       doGenerateSubmoduleConfigurations: false,
       extensions                       : [[$class : 'PreBuildMerge',
                                            options: [mergeStrategy: 'DEFAULT', fastForwardMode: 'NO_FF', mergeRemote: 'origin', mergeTarget: 'master']]],
       submoduleCfg                     : [],
       userRemoteConfigs                : [[credentialsId: '<id>', url: '[email protected]:<repo-name>/<project-name>',name: 'origin',
        refspec: '+refs/pull/*:refs/remotes/origin/pr/*',]]]
        sshagent (credentials: ['<credentialId>']) {
           sh "git status"
           sh "git push origin master"

        }
        sh 'git log -n 10'

jenkin显示日志如下:

git checkout -f cf1dbfbd9e1f52bf41738884a5c48ab1a59e5104 [Pipeline] sshagent

[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-eAaXoe8YpGdR/agent.28743
SSH_AGENT_PID=28746

[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
[Search-UI] Running shell script
+ git status
HEAD detached at origin/master
nothing to commit, working tree clean
[Pipeline] sh
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 28746 killed;
[ssh-agent] Stopped.
[Search-UI] Running shell script
+ git push origin master
Everything up-to-date

但无法看到git的任何变化。还有什么我需要配置

git jenkins github groovy
2个回答
0
投票
  options: [mergeStrategy: 'DEFAULT', fastForwardMode: 'NO_FF', mergeRemote: 'origin', mergeTarget: ghprbTargetBranch]]]

你已经提到mergeTarget为“ghprbTargetBranch”

mergeTarget是您要合并的分支。

 sh "git push origin $ghprbTargetBranch"

以上两个命令不匹配...您可能在上面的命令中错误地添加了$。

如果没有,那么你已经提到了$ ghprbTargetBranch,即它可以/可以为它分配一个值,就像这样 ghprbTargetBranch = master

基于日志,我猜你正在尝试合并到主人。如果是这种情况,那么您需要将mergeTarget更改为master。

如果没有,即mergeTarget = ghprbTargetBranch是你想要合并的分支,那么 sh命令,即$ ghprbTargetBranch(赋值给它的值不是ghprbTargetBranch)可能不同。

希望能帮助到你 :)


0
投票

找到答案如下:

sshagent(credentials: ['<credentialId>']) {
              sh 'git checkout master'
              sh 'git merge --no-ff $sha1'
              sh 'git push origin master'
            }
© www.soinside.com 2019 - 2024. All rights reserved.