jenkins-pipeline

How to use Jenkins String Parameter in pipeline

不想你离开。 提交于 2021-01-29 07:57:41
问题 We am using Jenkins Pipeline to configure jobs in jenkins. For a bunch of jobs we need user input for which we use parameterised build where user can input parameter values and later we use the values in our .jenkinsfile in sh like sh "./build-apply.sh ${accountnumber} ${volumename} ${vpcname} services ${snapshotid}" This used to work with Jenkins 2.16 Pipeline 2.3 Groovy 2.15 However, when I rebuild Jenkins to: 2.16 or latest 2.26 Pipeline 2.5 Pipeline: Groovy 2.19 The above sh stopped

ERROR npm ERR! errno 126, when running postman collections using maven in Jenkins

混江龙づ霸主 提交于 2021-01-29 07:45:14
问题 *I am trying to run postman collections using Maven in Jenkins. I get below errors when the pipeline is run. I can run these locally with 'mvn clean verify' in intellij and all tests run successfully. I am bit lost as how to solve this issue and looking for some help.:- [INFO] --- frontend-maven-plugin:1.6:npm (merge) @ ihtests --- [INFO] Running 'npm run shipment-tests' in /var/jenkins/workspace/com.tcel_intests_merge/temp [INFO] [INFO] > postman-newman-jenkins@1.0.0 shipment-tests /var

Use special agent for whole pipeline when a condition is met

浪子不回头ぞ 提交于 2021-01-29 07:44:20
问题 There is declarative pipeline. In the beginning of pipeline block the agent selection is made using agent directive. Label-based selection is being conducted. Agent selected this way is the standard/default agent. How to set for whole pipeline a special agent when certain condition is met? The plan is to do condition check based on pipeline's one parameter >> can that work? What are the points the chosen approach needs to address? Current solution blueprint: Groovy code prior to pipeline

Use special agent for whole pipeline when a condition is met

北城余情 提交于 2021-01-29 07:30:21
问题 There is declarative pipeline. In the beginning of pipeline block the agent selection is made using agent directive. Label-based selection is being conducted. Agent selected this way is the standard/default agent. How to set for whole pipeline a special agent when certain condition is met? The plan is to do condition check based on pipeline's one parameter >> can that work? What are the points the chosen approach needs to address? Current solution blueprint: Groovy code prior to pipeline

jenkins pipeline : How to execute a function on a list of agents in parallel?

本小妞迷上赌 提交于 2021-01-29 05:22:48
问题 I have a bunch of nodes serving labels rhel6 , rhel7 . How do I execute myFunc() on any 2 nodes of rhel6 and any 3 nodes rhel7 - in parallel ? def slaveList = ['rhel6', 'rhel6', 'rhel7', 'rhel7', 'rhel7'] def stageFunc (String slaveLabel) { return { // Run this stage on any available node serving slaveLabel agent { label "${slaveLabel}" } // Error shown here. stage { myFunc() } } } pipeline { agent any stages { stage('Start') { steps { script { def stageMap = [:] def i = 0 slaveList.each { s

How to setup a multiline parametrized cron job in Jenkins Scripted Pipeline?

被刻印的时光 ゝ 提交于 2021-01-29 02:49:50
问题 So this is working fine: properties([ //https://stackoverflow.com/questions/35370810/how-do-i-use-jenkins-pipeline-properties-step parameters([ //note here that the default will be the element you have as a first choice in the array choice(name: 'environmentName', choices: ['PROD', 'STAGE'], description: 'Choose the environment you want to run automation tests'), ]), //explained here: https://stackoverflow.com/questions/44113834/trigger-hourly-build-from-scripted-jenkinsfile //recall that ANY

How to use pom version in shell command in jenkinsfile?

∥☆過路亽.° 提交于 2021-01-28 20:53:45
问题 I am trying to get pom.xml version within Jenkinsfile and then use that version in a shell script. This gives the exception bad substitution when trying to use pom.version . What is the correct syntax to pass the pom version? script { def pom = readMavenPom file: 'pom.xml' withCredentials(...) { sh '''#!/bin/bash cp "${WORKSPACE}/target/stats-${pom.version}-shaded.jar" /xyz ''' } } I installed Pipeline Utility Steps plugin for readMavenPom cmd but didn't restart Jenkins. Is it necessary to

When running an ansible playbook via a shell script in Jenkins pipeline, the echo output is buffered and does not show in real time

吃可爱长大的小学妹 提交于 2021-01-28 20:00:53
问题 So below I have attached my pipeline code for Jenkins. The runansible.sh script takes in the parameters given and then proceeds to run an ansible playbook based on the paramMode value. When kicking off the shell script in a terminal I get realtime output of the ansible playbook running, but when using the Jenkins pipeline I just get the loading cogwheel during the echo stage. I do not get any echo output until the whole playbook has completed and then it spits it out all at once. I need to be

How to perform when..else in declarative pipeline

杀马特。学长 韩版系。学妹 提交于 2021-01-28 14:40:56
问题 I'm using a declarative pipeline. This part works: steps { script { if ('xxx' == 'cloud') { sh 'xxx' } else { sh 'xxx' } } } But I want to follow the more declarative pipeline syntax using when. I tried something like this: stage ('Newman run') { when { expression { "xxx" == "cloud" } } steps { echo 'Use proxy for cloud' sh 'xx' } when { expression { "cloud" == "cloud" } } steps { echo 'Do not use proxy (non-cloud)' sh 'xxx' } But it didn't work. How I can specify a sort of ' else ' statement

How to dynamically add all methods of a class into another class

僤鯓⒐⒋嵵緔 提交于 2021-01-28 14:22:51
问题 I have a global shared library on Jenkins implicitly loaded on all pipelines, then my Jenkinsfile is like that: new com.company.Pipeline()() And then the shared library has on directory src/com/company some files, below the Pipeline.groovy class: package com.company import static Utils.* def call() { // some stuff here... } The problem is, this way I have to static declare all methods, thus I lose the context and cannot access jenkins' methods easly without the Pipeline class' instance. As