【发布时间】:2018-08-16 23:06:24
【问题描述】:
我在 Jenkins 中使用管道的环境已经配置了来自 SCM 的管道脚本,该脚本然后使用 groovy 文件来处理管道内的阶段/作业。该脚本位于主分支的 Bitbucket 上。
每次 jenkins 作业启动时,它都会调用 master 分支,它运行没有问题,并且运行管道的各个阶段。
现在我在 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 文件会执行将要部署的代码的步骤。它不运行任何詹金脚本。它说“master”的地方是要部署的maser代码,而不是部署脚本。
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'
【问题讨论】:
-
一切看起来都很好...您验证了控制台输出中的提交 ID 吗?...您可以通过隐藏机密信息来共享控制台输出...
-
在那里我编辑并添加了它。可以看到 3 个分支,但是 master 正在运行。我希望该工作运行我的分支“DEVOPS-568-pipeline-ci”
-
我包括开始运行主分支作业的部分。然后作业成功运行,管道正常结束,但只有主分支
-
你能分享一下“checkout scm”发生的管道脚本吗?
-
脚本只包含这个:@Library("gp-extractor-deploy") _ DeployExtractor { confiFileId = "extractor-conf.properties" serverIp = 'xxxx' slackChannel = '#xxxxx' } 其中调用一个运行所有作业/步骤的 groovy 文件
标签: jenkins groovy jenkins-pipeline