来自不同分支机构的SCM的Jenkins管道不工作

yacmzcpb  于 2022-09-20  发布在  Jenkins
关注(0)|答案(0)|浏览(136)

我在Jenkins中的管道环境中工作,该环境已经从SCM配置了管道脚本,然后SCM使用groovy文件来处理管道中的阶段/作业。这些脚本位于主分支中的BitBucket上。

每次Jenkins作业启动时,它都会调用主分支,并且运行时没有任何问题,并且管道的各个阶段都会运行。

现在,我在BitBucket上创建了一个新的分支,并修改了groovy文件以包括更多步骤(如运行单元测试等),我希望Jenkins运行该脚本,但要使用我指定的分支(我创建的那个分支)。

问题是,即使我在“分支说明符”中指定了我的分支,Jenkins仍然运行主分支。以下是我配置的一些图像。
如何指定我想要在SCM的管道脚本上运行的分支?

Lightweight checkout support not available, falling back to full checkout.
Checking out git git@bitbucket.xxxxxx/xxxxxx.git into /data/jobs/extractor-pipeline-test-dev/workspace@script to read extractor-dev/Jenkinsfile
Cloning the remote Git repository
Cloning repository git@bitbucket.org:xxxxxx/xxxxxxxxxx.git
 > /usr/bin/git init /data/jobs/extractor-pipeline-test-dev/workspace@script # timeout=10
Fetching upstream changes from git@bitbucket.org:xxxx/xxxxxx.git
 > /usr/bin/git --version # timeout=10
 > /usr/bin/git fetch --tags --progress git@bitbucket.org:xxxxxx/deploy.git +refs/heads/*:refs/remotes/origin/*
 > /usr/bin/git config remote.origin.url git@bitbucket.org:xxxxx/deploy.git # timeout=10
 > /usr/bin/git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > /usr/bin/git config remote.origin.url git@bitbucket.org:xxxxxxx/deploy.git # timeout=10
Fetching upstream changes from git@bitbucket.org:xxxxx/deploy.git
 > /usr/bin/git fetch --tags --progress git@bitbucket.org:grydev/gp_deploy.git +refs/heads/*:refs/remotes/origin/*

**Seen branch in repository origin/DEVOPS-568-pipeline-ci

Seen branch in repository origin/dev
Seen branch in repository origin/master**
Seen 3 remote branches
 > /usr/bin/git tag -l # timeout=10
Checking out Revision e3270789a8181b26464f878bfccdf39b3fdabcb0 (master)
Commit message: " ....."
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f e3270789a8181b26464f878bfccdf39b3fdabcb0
 > /usr/bin/git rev-list e3270789a8181b26464f878bfccdf39b3fdabcb0 # timeout=10

这是groovy文件,但是groovy文件执行将要部署的代码的步骤。它不运行任何Jenkin脚本。其中,它说“master”是要部署的主代码,而不是部署脚本。

Groovy文件:

def call(body) {

    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    body()

    def artifactName = 'imp'
    def artifactExt = '.war'
    def artifactVersion = '0.0.1'

    def buildPath = 'target/'
    def warFile = artifactName + '-' + artifactVersion + artifactExt
    def warPath = buildPath + warFile
    def warNoVersion = artifactName + artifactExt

    def deployPath = '/var/lib/tomcat8/webapps/'
    def deployFile = deployPath + warNoVersion

    node {
        // Clean workspace before doing anything
        //deleteDir()

        try {

            stage ('Code Checkout') {
                git branch: 'master',
                    credentialsId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                    url: 'ssh://git@bitbucket.org/xxxxx/xxxximporter'

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题