Parallel Stages with parallel input message in Jenkins pipe line - jenkins-pipeline

I have the following pipeline:
pipeline {
agent any
stages {
stage('CI') {
parallel {
stage('גמלאות') {
steps {
input message: "Pass Sanity?"
}
}
stage('וועדות') {
steps {
input message: "Pass Sanity?"
}
}
stage('מבוטח') {
steps {
input message: "Pass Sanity?"
}
}
}
}
}
}
I'm expecting to see in the UI 3 option to select in each stage. but getting only one instead.
If I will look at tradinall console then I will be able to select if to proceed or to abort.
Is there a way to get this function thru the UI?
Here is an example of the UI:

It seems that the code is correct. The problem is with the Jenkins plugin.
I mooved to work with Blueocean plugin, and now it seems to work fine:

Related

Unable to do robot framework reports collection in Jenkins

I'm trying to run 4 test scripts in parallel. I want to store the output.xml file for each test script in the following manner-
Test_1 -> output1.xml
Test_2 -> output2.xml
.
.
Test_4 -> output3.xml
and combine them together and generate one single report.html file
I'm getting some errors related to the output.xml file location.
There is my script in Jenkins to run the robot-
pipeline {
agent any
triggers {
cron('H */4 * * 1-5')
}
stages {
stage('Testing') {
parallel{
stage('Testing- Operator') {
steps {
sh '''robot //var//jenkins_home//workspace//Testing_Operator//Operator.robot
robot archiveDirName:\'robot-plugin\',logFileName: \'**/log*.html\',outputFileName:\'**/output*.xml\',outputPath:\'/var/jenkins_home/workspace/Testing_Pipeline\',overwriteXAxisLabel: \'\',reportFileName:\'**/report*.html\''''
}
}
stage('Testing -Manager') {
steps {
sh '''robot //var//jenkins_home//workspace//Testing_Manger//Manager.robot
robot archiveDirName:\'robot-plugin\',logFileName: \'**/log*.html\',outputFileName:\'**/output*.xml\',outputPath:\'/var/jenkins_home/workspace/Testing_Pipeline\',overwriteXAxisLabel: \'\',reportFileName:\'**/report*.html\''''
}
}
stage('Testing -Admin') {
steps {
sh '''robot //var//jenkins_home//workspace//Testing_Admin//Admin.robot
robot archiveDirName:\'robot-plugin\',logFileName: \'**/log*.html\',outputFileName:\'**/output*.xml\',outputPath:\'/var/jenkins_home/workspace/Testing_Pipeline\',overwriteXAxisLabel: \'\',reportFileName:\'**/report*.html\''''
}
}
stage('Testing -Owner') {
steps {
sh '''robot //var//jenkins_home//workspace//Testing_Owner//Owner.robot
robot archiveDirName:\'robot-plugin\',logFileName: \'**/log*.html\',outputFileName:\'**/output*.xml\',outputPath:\'/var/jenkins_home/workspace/Testing_Pipeline\',overwriteXAxisLabel: \'\',reportFileName:\'**/report*.html\''''
}
}
}
}
}
}
Here is the error-
Output: /var/jenkins_home/workspace/Testing_Pipeline/output.xml
[ ERROR ] Reading XML source '/var/jenkins_home/workspace/Testing_Pipeline/output.xml'
failed: ParseError: not well-formed (invalid token): line xx, column xx
What could be the possible cause of the error? Is the syntax correct?
Probably the output.xml is broken due to running robot in parallel.
What you can do is for all the robot commands to use the flag for a different output path (or filename), and in a final stage call rebot to produce the final report and logs.

Is there a way to move the entire post {} build section in Jenkinsfile to the global pipeline library?

I'm relatively new to Jenkins pipelines, but having implemented already a few, I've realised I need to start using jenkins shared library before I go mad.
Have already figured out how to define some repetitive steps in the library and call them with less clutter from Jenkinsfile, but not sure if the same thing can be done for the entire post build section (thought I've read about to how to define the entire pipeline in the lib and similar), as this is pretty much static end of every single pipeline code:
#Library('jenkins-shared-library')_
pipeline {
agent none
stages {
stage ('System Info') { agent any
steps { printSysInfo() }
}
stage ('Init'){ agent {label 'WinZipSE'}
steps { init('SCMroot') }
}
stage('Build') { agent any
steps { doMagic() }
}
}
// This entire 'post {}' section needs to go to a shared lib
// and be called just with a simple methed call, e.g.
// doPostBuild()
post {
always {
node ('master') {
googlechatnotification (
message: '[$BUILD_STATUS] Build $JOB_NAME $BUILD_NUMBER has finished',
url: 'id:credential_id_for_Ubuntu')
step (
[$class: 'Mailer',
recipients: 'sysadmins#example.com me#example.com',
notifyEveryUnstableBuild: true,
sendToIndividuals: true]
)
}
}
success {
node ('master') {
echo 'This will run only if successful'
}
}
failure {
node ('master') {
echo 'This will run only if failed'
}
}
// and so on
}
}
I just dunno how to syntactically achieve that. For sure, I can define the entire post build section an a lib/var like: doPotBuild.groovy
def call () {
post {...}
}
but how I will eventually call it from within my Jenkinsfile outside of that defined post {} build block section (AKA stages).
I can call it within some stage('post build){doPostBuild()}, but it won't serve the way how the true post {} section is supposed to work, e.g. it won't get executed it there was failure in one of the previous stages.
Any thoughts on that and mainly working examples?
I am not entirely if this will work as I don't use declarative pipelines, so am unsure how rigid the top level structure is. But I would revert to a script block.
#Library('jenkins-shared-library')_
pipeline {
agent none
stages {
stage ('System Info') { agent any
steps { printSysInfo() }
}
stage ('Init'){ agent {label 'WinZipSE'}
steps { init('SCMroot') }
}
stage('Build') { agent any
steps { doMagic() }
}
}
// This entire 'post {}' section needs to go to a shared lib
// and be called just with a simple methed call, e.g.
// doPostBuild()
script {
doPostBuild()
}
}

exit declarative pipeline prematurely based on script output

While I am aware of this question clean way to exit declarative Jenkins pipeline as success I am to green to understand how to put it to use (from where does the skipBuild variable come?).
I have a script that determines whether the pipeline should continue or not but I am unsure how to piece it together (I am free to construct the script as needed).
pipeline {
agent {
docker { image 'python:3-alpine' }
}
stage('Should I continue') {
steps {
python should_i_continue.py
}
when { ? == true }
stages {
...
}
}
}
I am aware that the capabilities increase tenfold if I use a scripted pipeline but I wonder if it is possible to do what I want with a declarative one?
You can use any custom variable, which you will set as true|false based on some condition in the steps of your pipeline and all stages that need to be executed based on that condition have to have following format:
stage('Should Continue?') {
setBuildStatus("Build complete", "SUCCESS");
when {
expression {skipBuild == true }
}
}
In other words to provide you a bit clean picture, check this abstract example:
node {
skipBuild = false
stage('Checkout') {
...
your checkout code here
...
}
stage('Build something') {
...
some code goes here
skipBuild = true
...
}
stage('Should Continue?') {
setBuildStatus("Build complete", "SUCCESS");
when {
expression {skipBuild == true }
}
}
}

How to ask user input only when branch matches master in Jenkinsfile pipeline?

I tried to use the following Jenkinsfile to ask input only on master branch and can't get the groovy grammer pass validation:
pipeline {
stage('Deploy') {
when {
branch 'master'
}
steps {
input(message: "Please input", parameters: [string(name: "VERSION", defaultValue="", description="")]
}
}
}
The error is:
java.lang.IllegalArgumentException: Expected named arguments but got [{name=VERSION, description=""}, null]
I searched a lot but didn't find a single one example about using input step in the Jenkinsfile with parameters.
Can anyone shed some light on this? Thanks in advance!
Finally find a way to do this, we should wrap the input with the script keyword.
stage('Deploy to k8s prod') {
when {
branch 'release-prod'
}
steps {
script {
env.VERSION = input message: '请输入参数', ok: '确定', parameters: [
string(name:'VERSION', description: "版本号")]
}
sh "echo ${env.VERSION}"
}
}
}

Need Help in Jenkins-Job DSL promotion

Iam working on creating a Build promotion using Jenkins-JOb DSL-Paramterized build.
My Scripts looks as,
Job('sampleMavenProj') {
triggers { scm("*/5 * * * *") }
scm { git('file:///work/SampleTest') }
rootPOM("pom.xml")
goals('clean')
wrappers {
preBuildCleanup()
release {
preBuildSteps {
maven {
rootPOM('pom.xml')
goals("build-helper:parse-version")
goals("versions:set")
}
}
postSuccessfulBuildSteps {
maven {
rootPOM('pom.xml')
goals("package")
}
}
}
}
}
promotions("") {
promotion("Development") {
icon("star-red")
conditions {
manual('')
}
actions {
shell('echo This is a DownStream Job;')
}
}
But when i build the JOb , it fails saying ,
Processing provided DSL script
ERROR: (script, line 31) No signature of method: script.promotions() is applicable for argument types: (java.lang.String, script$_run_closure2) values: [, script$_run_closure2#4fcac57f]
Finished: FAILURE
Which is at , promotions area. Please let me on this.
Thanks for all the responses.
Seems like the Prompted build plugin that i am using is not working. I have to use the 2.26 version from"https://github.com/Russell-IO/promoted-builds-plugin/releases" to use the code. This solved my issues. thanks

Resources