我正在探索Jenkins 2.0管道.到目前为止,我的文件非常简单.
node { stage "checkout" git([url:"github/luxengine/math.git"]) stage "build" echo "Building from pipeline" }我似乎找不到任何方法来设置git检出的目录.我也找不到与此有关的任何类型的文档.我发现 jenkinsci.github.io/job-dsl-plugin/但这似乎与我在其他教程中看到的不一样.
解决方案澄清
看起来您正在尝试配置管道作业(以前称为作为工作流程).这种工作与工作DSL 截然不同. >
管道作业的目的是:
安排可以跨越多个构建从属的长期活动.适用于构建管道(以前称为工作流)和/或组织不容易适合自由式工作类型的复杂活动.
何为工作DSL:
...允许使用DSL以编程方式创建项目.将作业创建工作推送到脚本中,使您能够自动化和标准化Jenkins安装,这与以前可能的一切不同.
解决方案
如果要将代码检出到特定目录,则将git步骤替换为更通用的SCM checkout步骤. 最终的管道配置应如下所示:
node { stage "checkout" //git([url:"github/luxengine/math.git"]) checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'checkout-directory']], submoduleCfg: [], userRemoteConfigs: [[url: 'github/luxengine/math.git']]]) stage "build" echo "Building from pipeline" }作为 Jenkins 2.0 和管道 DSL,请使用内置的 Snippet Generator 或文档.
I'm exploring Jenkins 2.0 pipelines. So far my file is pretty simple.
node { stage "checkout" git([url:"github/luxengine/math.git"]) stage "build" echo "Building from pipeline" }I can't seem to find any way to set the directory that git will checkout to. I also can't find any kind of documentation related to that. I found jenkinsci.github.io/job-dsl-plugin/ but it doesn't seem to match what I see on other tutorials.
解决方案Clarification
Looks like you are trying to configure Pipeline job (formerly known as Workflow). This type of job is very distinct from Job DSL.
The purpose of Pipeline job is to:
Orchestrates long-running activities that can span multiple build slaves. Suitable for building pipelines (formerly known as workflows) and/or organizing complex activities that do not easily fit in free-style job type.
Where as Job DSL:
...allows the programmatic creation of projects using a DSL. Pushing job creation into a script allows you to automate and standardize your Jenkins installation, unlike anything possible before.
Solution
If you want to checkout your code to specific directory then replace git step with more general SCM checkout step. Final Pipeline configuration should look like that:
node { stage "checkout" //git([url:"github/luxengine/math.git"]) checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'checkout-directory']], submoduleCfg: [], userRemoteConfigs: [[url: 'github/luxengine/math.git']]]) stage "build" echo "Building from pipeline" }As a future reference for Jenkins 2.0 and Pipeline DSL please use built-in Snippet Generator or documentation.
更多推荐
Jenkinfile DSL如何指定目标目录
发布评论