Jenkinsfile中的git push标签失败

时间:2020-04-19 09:07:33

标签: git jenkins jenkins-pipeline git-tag

我正在尝试在CI的末尾添加“ git push tag”功能,以便跟踪通过CI的提交。我知道有一些插件,但是它们的行为与我尝试的有所不同。 那就是我在控制台中使用“ git push”失败的原因:

    [Pipeline] sh
DEBUG Print - git tag -a <generated-tag-name> -m 'CI-Passed'
DEBUG Print - git push origin <branch> <generated-tag-name>
error: src refspec <branch> does not match any.
error: failed to push some refs to 'https://github.com/<account>/<account>.git'
Error when executing success post condition:
hudson.AbortException: script returned exit code 1
    at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.handleExit(DurableTaskStep.java:569)
    at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.check(DurableTaskStep.java:515)
    at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.run(DurableTaskStep.java:461)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
[Pipeline] echo

但是,当我将git push命令复制到控制台并将其粘贴时,推送成功。 Jenkins如何从我的桌面对git命令进行不同的处理?

4 个答案:

答案 0 :(得分:1)

这可能是由于配置选项push.default的不同设置引起的。 (使用git config push.default打印当前值)

尝试在命令中显式指定本地和远程引用名称(无论如何,这都是脚本中的最佳做法):

git push origin branch:branch tagname:tagname

答案 1 :(得分:0)

感谢您的回复,我尝试这样做并收到错误消息

Error when executing success post condition:hudson.AbortException: script returned exit code 1
at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.handleExit(DurableTaskStep.java:569)
at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.check(DurableTaskStep.java:515)
at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.run(DurableTaskStep.java:461)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

答案 2 :(得分:0)

因此,为了回答这个问题,我假设您的代码已在要标记的分支上检查过。如果文件有任何更改,请按以下顺序执行命令。

git add -A    // This command will stage all the files that have been changed. 
git commit -m "added changes" // This command wil commit the changes and will create a commit id you need to tag
git tag <tag name>
git push https://${GIT_AUTHOR_NAME}:${GIT_PASSWORD}@github.com<repository>.git <tag name>"

答案 3 :(得分:0)

我尝试了一个不同的push命令,尽管我不完全了解我的台式机与Jenkins Master / Slave之间的git输出差异,但它仍然有效

    def FIXED_GIT_URL= GIT_URL.replace('https://','git@').replace('com/','com:')

    status = sh(script: """#!/bin/bash
            export REP_ROOT=`git rev-parse --show-toplevel`
            export Tag=${GitTag}
            export Git_url=${FIXED_GIT_URL}
            git tag -a \${Tag} -m \\'CI-Passed\\'               
            git push \${Git_url} \${Tag}
                    """)
相关问题