Jenkinfile DSL如何指定目标目录 [英] Jenkinfile DSL how to specify target directory

查看:499
本文介绍了Jenkinfile DSL如何指定目标目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在探索Jenkins 2.0管道.到目前为止,我的文件非常简单.

node {
    stage "checkout"
    git([url:"https://github.com/luxengine/math.git"])

    stage "build"
    echo "Building from pipeline"
}

我似乎找不到任何方法来设置git检出的目录.我也找不到与此有关的任何类型的文档.我发现 https://jenkinsci.github.io/job-dsl-plugin/但这似乎与我在其他教程中看到的不一样.

解决方案

澄清

看起来您正在尝试配置管道作业(以前称为作为工作流程).这种工作与工作DSL 截然不同. >

管道作业的目的是:

安排可以跨越多个构建从属的长期活动.适用于构建管道(以前称为工作流)和/或组织不容易适合自由式工作类型的复杂活动.

何为工作DSL:

...允许使用DSL以编程方式创建项目.将作业创建工作推送到脚本中,使您能够自动化和标准化Jenkins安装,这与以前可能的一切不同.

解决方案

如果要将代码检出到特定目录,则将git步骤替换为更通用的SCM checkout步骤. 最终的管道配置应如下所示:

 node {
    stage "checkout"
    //git([url:"https://github.com/luxengine/math.git"])
    checkout([$class: 'GitSCM', 
        branches: [[name: '*/master']], 
        doGenerateSubmoduleConfigurations: false, 
        extensions: [[$class: 'RelativeTargetDirectory', 
            relativeTargetDir: 'checkout-directory']], 
        submoduleCfg: [], 
        userRemoteConfigs: [[url: 'https://github.com/luxengine/math.git']]])

    stage "build"
    echo "Building from pipeline"
}
 

作为 Jenkins 2.0

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 https://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:"https://github.com/luxengine/math.git"])
    checkout([$class: 'GitSCM', 
        branches: [[name: '*/master']], 
        doGenerateSubmoduleConfigurations: false, 
        extensions: [[$class: 'RelativeTargetDirectory', 
            relativeTargetDir: 'checkout-directory']], 
        submoduleCfg: [], 
        userRemoteConfigs: [[url: 'https://github.com/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如何指定目标目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆