我想进行Jenkins git 插件文档clean before checkout中描述的操作:
签出前清理 在每次签出之前通过删除所有未跟踪的文件和目录(包括 .gitignore 中指定的文件和目录)来清理工作区。...
但是如何将此选项添加到作为第一步执行的默认结账步骤中?
我觉得它应该是 git 插件扩展的一个选项,可以包含到optionsJenkinsfile 块中,如文档中所述:
options 指令允许从 Pipeline 本身配置特定于 Pipeline 的选项。Pipeline 提供了许多这样的选项,例如 buildDiscarder,但它们也可能由 插件提供......
但是如何知道这个插件提供了哪些选项及其名称呢?在文档中没有找到它,我也可能是错误的,clean before checkout应该放在optionsJenkinsfile 块中。
请帮忙。
jenkins jenkins-plugins jenkins-pipeline jenkins-declarative-pipeline jenkins-git-plugin
我有一个具有以下结构的共享库存储库:
(root)
+- src
| +- com
| +- company
| +- DeploySteps.groovy
+- vars
| +- MainDeploySteps.groovy
Run Code Online (Sandbox Code Playgroud)
该库通过 Jenkinsfile 导入到作业中,如下所示:
library identifier: 'jenkinslib@master', retriever: modernSCM(
[$class : 'GitSCMSource',
remote : 'git@url.to.git:jenkinslib.git',
credentialsId: 'jenkins-credentials'])
Run Code Online (Sandbox Code Playgroud)
src/com/company/DeploySteps.groovy 中的存储库中的类有一个方法(例如 CheckoutSCM),我希望将其包含在 Jenkinsfile 中。
部署步骤.groovy:
def CheckoutSCM() {
useful steps here
}
Run Code Online (Sandbox Code Playgroud)
是否有可能在 Jenkinsfile 中包含此特定方法,例如
import com.company.DeploySteps
Run Code Online (Sandbox Code Playgroud)
然后像这样使用它:
CheckoutSCM('repo-here')
Run Code Online (Sandbox Code Playgroud)
稍后在 Jenkinsfile 中?我多次阅读文档src,但没有找到答案是否可以从文件夹导入某些内容,而不仅仅是从vars.
为什么我要问,因为现在当 import:import com.company.DeployUtils然后尝试调用方法时,CheckoutSCM()会在 Jenkins 控制台输出中看到错误:
java.lang.NoSuchMethodError:在步骤中找不到这样的 DSL 方法“CheckoutSCM”
下面列出了可用的方法,其中CheckoutSCM肯定没有我的方法)
那么,是否可以将类从src文件夹导入到 …
jenkins jenkins-groovy jenkins-pipeline jenkins-shared-libraries
Jenkins 有一个很好的相对全面的关于 Jenkinsfile 语法的文档。但是我仍然没有找到答案是否可以在管道的顶层进行流量控制?从字面上看,if仅在pipeline {}部分(声明性)中包含一些内容,例如:
pipeline {
if (bla == foo) {
triggers {
...configuration
}
}
Run Code Online (Sandbox Code Playgroud)
或者
pipeline {
triggers {
if (bla == foo) {
something...
}
}
}
Run Code Online (Sandbox Code Playgroud)
triggerssection 是一个只能包含一次并且只能包含在该pipeline部分中的部分。但是if语句似乎只适用于阶段级别。
有谁知道如何triggers有条件地包含指令中的某些内容,例如, 或有条件地包含指令本身?
jenkins jenkins-groovy jenkins-pipeline jenkins-declarative-pipeline