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

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

问题描述

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

节点{阶段结帐"git([url:"https://github.com/luxengine/math.git"])构建"阶段echo "从管道构建"}

我似乎找不到任何方法来设置 git 将结帐到的目录.我也找不到任何与此相关的文档.我找到了 https://jenkinsci.github.io/job-dsl-plugin/但它似乎与我在其他教程中看到的不符.

解决方案

澄清

您似乎正在尝试配置 Pipeline 作业(以前称为作为工作流).这种类型的工作与 Job DSL 非常不同.p>

Pipeline 作业的目的是:

<块引用>

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

作为 Job DSL:

<块引用>

...允许使用 DSL 以编程方式创建项目.将作业创建推送到脚本中可让您自动化和标准化 Jenkins 安装,这与以前的任何事情都不同.

解决方案

如果您想将代码签出到特定目录,请将 git 步骤替换为更通用的 SCM checkout 步骤.最终的 Pipeline 配置应如下所示:

node {阶段结帐"//git([url:"https://github.com/luxengine/math.git"])checkout([$class: 'GitSCM',分支:[[名称:'*/master']],doGenerateSubmoduleConfigurations:假,扩展名:[[$class: 'RelativeTargetDirectory',relativeTargetDir: '结帐目录']],子模块配置:[],userRemoteConfigs: [[url: 'https://github.com/luxengine/math.git']]])构建"阶段echo "从管道构建"}

作为 Jenkins 2.0Pipeline DSL 请使用内置 Snippet Generator文档.

I'm exploring Jenkins 2.0 pipelines. So far my file is pretty simple.

node {
    stage "checkout"
    git([url:"https://github.com/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 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.

这篇关于Jenkinsfile DSL如何指定目标目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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