我正在将一项工作从多任务迁移到Jenkins声明式管道工作。我无法在多个执行程序上运行并行步骤。
例如,在下面的管道中,我在运行管道时仅看到一个执行程序。
我想知道为什么只使用一个执行器。想法是,每个并行步骤都将获取将构建docker映像的make目标。
pipeline {
agent none
stages {
stage('build libraries') {
agent { label 'master' }
steps {
parallel(
"nodejs_lib": {
dir(path: 'nodejs_lib') {
sh 'sleep 110'
}
},
"python_lib": {
dir(path: 'python_lib') {
sh 'sleep 100'
}
}
)
}
}
}
options {
ansiColor('gnome-terminal')
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '30'))
timestamps()
}
}
Run Code Online (Sandbox Code Playgroud) 我尝试并行化动态定义的函数集,如下所示:
def somefunc() {
echo 'echo1'
}
def somefunc2() {
echo 'echo2'
}
running_set = [
{ somefunc() },
{ somefunc2() }
]
pipeline {
agent none
stages{
stage('Run') {
steps {
parallel(running_set)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我最终得到的是:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 17: No "steps" or "parallel" to execute within stage "Run" @ line 17, column 9.
stage('Run') {
Run Code Online (Sandbox Code Playgroud)
虽然步骤是在"运行"阶段中定义的.无论如何,我想要实现的是一组动态定义的并行执行的函数.
groovy jenkins jenkins-pipeline jenkins-declarative-pipeline
这是上一篇文章的后续问题,似乎没有比“看起来很有希望”更多的答案:
这是CICD管道的主要功能差距。声明式(1.2.9)的当前“输入步骤”要求整个管道在管道完成之前必须等待输入步骤(否则超时将使您以后无法重新触发)。根据代理的作用域,它还可以容纳执行程序,或者要求您必须为每个构建步骤启动一个新的从属。
这是我最接近的解决方案,不会耗尽执行程序(管道级别为``无代理'',在此描述的所有阶段都定义了代理):https://jenkins.io/blog/2018/04/09 / whats-in-declarative /),但是在每个构建步骤中启动一个新的slave似乎很浪费时间,并且在持久化工作空间时还需要考虑其他因素。最终提供的解决方案是为输入抛出“超时”,但这仍然行不通,因为那样一来,您将永远无法将该构建移至下一个阶段,而需要重新构建。
这里的任何解决方案或建议将不胜感激。
user-input jenkins jenkins-pipeline jenkins-declarative-pipeline
我的Jenkins声明性管道具有以下后期处理措施:
mail to: '<snip>',
subject: "Status of pipeline: ${currentBuild.fullDisplayName}",
body: "${env.BUILD_URL} has result ${currentBuild.result}"
Run Code Online (Sandbox Code Playgroud)
构建成功后,电子邮件正文的内容为:
<job name> has result null
Run Code Online (Sandbox Code Playgroud)
我知道作业成功时$ {currentBuild.result}“的值为null,但这对用户不方便。建议在正文中打印“ SUCCESS”(或“ FAILURE”等)的建议方式是什么信息?
我有一些构建逻辑,比如发布,我希望Jenkins只在构建Git标签时执行.如何使用Jenkin的Declarative Pipeline实现这一目标?
换句话说,我正在尝试构建与Travis CI部署标签功能相当的功能:
deploy:
[...]
on:
tags: true
Run Code Online (Sandbox Code Playgroud)
有一个内置条件来检查分支,但我没有看到一个指示标记.
jenkins jenkins-pipeline multibranch-pipeline jenkins-declarative-pipeline
我正在尝试升级我当前的回归基础设施以使用管道插件,我意识到有两种方法:scripted pipeline和declarative pipeline.通过多篇文章,我意识到这declarative pipeline是更具前瞻性和更强大的功能,因此我倾向于使用它.但似乎有以下限制,我不希望在我的设置中:
该jenkinsfile需求是在库中.我不想让我jenkinsfile留在代码库中.
由于jenkinsfile需要在SCM中.这是否意味着我无法测试文件中的任何修改,直到我检查到存储库.
上述任何细节都非常有用.
我有一个Jenkinsfile用于这样的多分支管道:
pipeline {
agent any
stages {
// ...
}
post {
failure {
mail to: 'team@example.com',
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Something is wrong with ${env.BUILD_URL}"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我只想在master分支上发送失败电子邮件。有没有办法使邮件步骤成为条件邮件?根据文档,when伪指令只能在内使用stage。
获取No such field found: field java.lang.String sinput错误而运行我的Jenkinsfile。
我开发了一个 Jenkinsfile,它可以接受用户输入,并进一步在远程机器上运行一个命令,将用户输入作为变量
stages {
stage("Interactive_Input") {
steps {
script {
def apiinput
def userInput = input(
id: 'userInput', message: 'This is my project',
parameters: [
string(defaultValue: 'None',
description: 'Enter the name of the service',
name: 'sinput'),
])
// Save to variables. Default to empty string if not found.
apiinput = userInput.sinput?:''
}
}
}
}
Run Code Online (Sandbox Code Playgroud) groovy jenkins jenkins-pipeline jenkins-declarative-pipeline
这是我的声明性 Jenkinsfile 的一个子集:
pipeline {
agent {
kubernetes {
yamlFile 'pod.yml'
defaultContainer 'tools'
}
}
stages {
stage('Init') { // <- this stage executes in Kubernetes and works very well
steps {
sh "echo init"
}
}
stage('Build') {
agent { label 'B202981' } // <- This wont work; B202981 is computer on my network
steps {
sh "echo build"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当此管道运行时,它会因异常而失败,您可以在此处看到该异常,而谷歌搜索此异常对我没有帮助。
java.lang.ClassCastException: hudson.slaves.DumbSlave cannot be cast to org.csanchez.jenkins.plugins.kubernetes.KubernetesSlave
at org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator$1.launch(ContainerExecDecorator.java:250)
at hudson.Launcher$ProcStarter.start(Launcher.java:455)
at org.jenkinsci.plugins.durabletask.WindowsBatchScript.doLaunch(WindowsBatchScript.java:83)
at org.jenkinsci.plugins.durabletask.FileMonitoringTask.launchWithCookie(FileMonitoringTask.java:106) …Run Code Online (Sandbox Code Playgroud) jenkins jenkins-declarative-pipeline kubernetes-jenkins-plugin
我有Jenkinsfile(脚本化管道)
def template1 = "spread_sshkeys"
node {
// Clean before build
stage('Checkout') {
deleteDir()
checkout scm
sh "git submodule foreach --recursive git pull origin master";
}
stage("import template ${template1}") {
script{
sh "ls -las; cd jenkins-ci-examples; ls -las";
jenkins_ci_examples.sub_module = load "jenkins-ci-examples/${template1}"
}
}
stage("run template ${template1}") {
sh "echo ${jenkins_ci_examples.sub_module}";
}
}
Run Code Online (Sandbox Code Playgroud)
想要转换为声明式之后
def template1 = "spread_sshkeys"
pipeline {
agent any
stages {
stage ("Checkout") {
steps {
deleteDir()
checkout scm
sh "git submodule foreach --recursive git pull …Run Code Online (Sandbox Code Playgroud) jenkins jenkins-job-dsl jenkins-groovy jenkins-pipeline jenkins-declarative-pipeline