Ошибка сборки Jenkins Bitbucket PR без уничтожения рабочего пространства - PullRequest
0 голосов
/ 20 декабря 2018

У меня есть сборка Дженкинса, как это

job('jenkinsjob') {
    description('')
    logRotator(7, -1, 7, -1)
    parameters {
        stringParam('PULL_REQUEST_ID','','Pull request ID (populated by Bitbucket Webhook)')
        stringParam('PULL_REQUEST_URL','','Pull request URL (populated by Bitbucket Webhook)')
        stringParam('PULL_REQUEST_TITLE','(no title)','Pull request title (populated by Bitbucket Webhook)')
    }
    authorization {
        ...
    }
    label('java')
    wrappers {
        timeout {
            elastic(300, 3, 30)
        }
        preScmSteps {
            steps {
                systemGroovyCommand('''def url = build.buildVariableResolver.resolve(\'PULL_REQUEST_URL\')
def id = build.buildVariableResolver.resolve(\'PULL_REQUEST_ID\')
def title = build.buildVariableResolver.resolve(\'PULL_REQUEST_TITLE\')
build.description = "PR #${id}: <a href=\'${url}\'>${title}</a>"''')
            }
            failOnError(true)
        }
    }
    scm {
        git {
            remote {
                name('origin')
                url('ssh://git@git.mycom.com/team/project.git')
            }
            branches('origin/pr/master', '*/release/**', '*/bugfix/**')
            extensions {
                // wipeOutWorkspace() // ***** comment out to speed out build. ******/
                localBranch('$GIT_BRANCH')
                mergeOptions {
                    remote('origin')
                    branch('master')
                    strategy('default')
                    fastForwardMode(FastForwardMergeMode.FF)
                }
            }
        }
    }
    triggers {
        ...
    }
    steps {
        shell('''
npm install
        ''')
      ...
    }
    publishers {
      ...
    }
}

Когда я использую wipeOutWorkspace, все работает нормально.Проблема в том, что установка npm занимает много времени, потому что это чистое рабочее пространство.

После комментирования wipeOutWorkspace сборка завершается с такой ошибкой:

Success build forhudson.plugins.groovy.SystemGroovy@20d4dc0f
> /usr/local/devtools/git-2.16.1/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> /usr/local/devtools/git-2.16.1/bin/git config remote.origin.url ssh://git@git.mycom.com/team/project.git # timeout=10
Fetching upstream changes from ssh://git@git.mycom.com/team/project.git
> /usr/local/devtools/git-2.16.1/bin/git --version # timeout=10
> /usr/local/devtools/git-2.16.1/bin/git fetch --tags --progress ssh://git@git.mycom.com/team/project.git +refs/heads/*:refs/remotes/origin/*
> /usr/local/devtools/git-2.16.1/bin/git rev-parse 0e8b897bf5b304a88d6a7f94a5fd01809d5c37c4^{commit} # timeout=10
> /usr/local/devtools/git-2.16.1/bin/git branch -a -v --no-abbrev --contains 0e8b897bf5b304a88d6a7f94a5fd01809d5c37c4 # timeout=10
Merging Revision 0e8b897bf5b304a88d6a7f94a5fd01809d5c37c4 (origin/feature/SCOPE-work123) to origin/master, UserMergeOptions{mergeRemote='origin', mergeTarget='master', mergeStrategy='default', fastForwardMode='--ff'}
> /usr/local/devtools/git-2.16.1/bin/git rev-parse origin/master^{commit} # timeout=10
> /usr/local/devtools/git-2.16.1/bin/git config core.sparsecheckout # timeout=10
> /usr/local/devtools/git-2.16.1/bin/git checkout -f origin/master
> /usr/local/devtools/git-2.16.1/bin/git branch -a -v --no-abbrev # timeout=10
> /usr/local/devtools/git-2.16.1/bin/git branch -D origin/master # timeout=10
FATAL: Could not checkout origin/master with start point origin/master
hudson.plugins.git.GitException: Command "/usr/local/devtools/git-2.16.1/bin/git branch -D origin/master" returned status code 1:
stdout:
stderr: error: Cannot delete branch 'origin/master' checked out at '<http://devbox.mycom.com:62381/cibuild/job/team123/job/project123/job/project/job/prbuild/ws/'>

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1799)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1772)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1768)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1415)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1427)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.deleteBranch(CliGitAPIImpl.java:2187)
Caused: hudson.plugins.git.GitException: Could not delete branch origin/master
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.deleteBranch(CliGitAPIImpl.java:2189)
    at hudson.plugins.git.GitAPI.deleteBranch(GitAPI.java:222)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2071)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:153)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:146)
    at hudson.remoting.UserRequest.perform(UserRequest.java:208)
    at hudson.remoting.UserRequest.perform(UserRequest.java:54)

Есть ли способ сделатьбыстрая сборка pr без необходимости каждый раз стирать рабочее пространство?

...