Jenkinfile DSL如何指定目标目录

编程入门 行业动态 更新时间:2024-10-16 00:22:34
本文介绍了Jenkinfile DSL如何指定目标目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在探索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如何指定目标目录

本文发布于:2023-08-05 02:03:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1301635.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:目标   目录   Jenkinfile   DSL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!