jenkins-groovy

Curl (bash) command not working in Jenkinsfile groovy script

回眸只為那壹抹淺笑 提交于 2019-12-11 21:47:30
问题 In my Jenkinsfile Groovy script, I have the following code; stage('Test the 500 log URLs') { steps { script { echo 'Testing the URLs from the 500 error access log...' sh '''#!/bin/bash while IFS= read -r line; do URL=`echo $line | awk '{print $2}' | sed 's/http:/https:/' ` RESULT=`curl -LI $URL -o /dev/null -w "%{http_code}\n" -s | tr -d '[:space:]' ` if [[ $RESULT != "200" ]] then echo "$RESULT $URL" fi done < tests/Smoke/logs_testing/500errors.txt ''' } } } The first parts of the file work

How to checkout shared library pipeline other then master

半城伤御伤魂 提交于 2019-12-11 18:45:11
问题 My Jenkins master doesn't have an executor and it can't have due to the design of Jenkins we have in our company. We have 2 worker node. When I add Pipeline shared library then by default Jenkins tries to checkout in master and fails due to obvious reasons as it can't find git as it is not available in Jenkins master. Cloning repository git@github.com:Test/jenkins-pipeline-shared.git > git init /var/lib/jenkins/workspace/rp-pipe_PR-675@libs/slackNotify # timeout=10 ERROR: Error cloning remote

Define Jenkins pipeline on an external file

点点圈 提交于 2019-12-11 16:49:29
问题 We have several pipeline jobs with the same structure and behavior: update an ansible repository, execute a playbook with some parameters whose value depends on the environment and test with inspec the execution. We've tried to abstract the general behavior in an external file. JenkinsfileAnsible: #!/usr/bin/env groovy import groovy.json.JsonOutput node { } def executePlaybook(environment){ pipeline{ agent any stages{ stage('Update repository'){ ... } stage('Esecute playbook'){ ... } stage(

error seeing when parsing the json response using groovy

自作多情 提交于 2019-12-11 15:36:52
问题 import groovy.json.JsonSlurper def testStepName = 'Adding_Users' def jsonSlurper = new JsonSlurper() def response = context.expand('$(testStepName#Response)') def usersInfomration = jsonSlurper.parseText(response) String userName = userInformation.name log.info UserName 来源: https://stackoverflow.com/questions/58326431/error-seeing-when-parsing-the-json-response-using-groovy

Groovy while loop not executed correctly

坚强是说给别人听的谎言 提交于 2019-12-11 15:27:30
问题 I've following simple while loop code in groovy - def count = 1 while(count <= 5) { println "$count" sleep(5000) println "Sleeping for 5 seconds" count++ } Which indicates that loop is executed only twice still second time Sleeping for 5 seconds is not run. Actually with this code, while block is expected to be executed 5 times. Can someone help to understand why such a weird behaviour? When this code is run, output is following - 1 Sleeping for 5 seconds 2 回答1: This works fine: ~ $ cat doit

passing items in two lists simultaneoulsy in each loop Jenkinsfile

为君一笑 提交于 2019-12-11 06:46:20
问题 I have a list foo = ['tea',''sugar','milk'] and col = ['black','white','pink'] what I am trying to do is nested loop def foo = ['tea','sugar','milk'] def col = ['black','white','pink'] [foo, col].transpose().each { x, y -> sh """aws deploy push --application-name "${x}" --source "${y}" """ } Desired Result --application-name "tea" --source "black" --application-name "sugar" --source "white" --application-name "milk" --source "pink" the result I am getting [Pipeline] script [Pipeline] {

Groovy - Convert a timestamp string to Epoch time in milliseconds

烂漫一生 提交于 2019-12-11 06:39:34
问题 I have a timestamp string as follows: String build_time=2017-11-20T21:27:03Z I want to convert it into epoch time in milliseconds as per the PST time zone such that my result is: long build_time_ms=1511299623000 How can I do this? 回答1: You can achieve this using java's java.time.* package. Below is working script and output from running groovy via docker. I haven't tried this within Jenkins though, and script may require adding appropriate def statements to avoid pipeline serialization issues

Change groovy variables inside shell executor in Jenkins pipeline

人盡茶涼 提交于 2019-12-11 03:34:37
问题 I have a Jenkins pipeline job where I am taking some build variables as input, and if the variables are not passed by the user, I execute a script and get the value of those variables. Later I have to use the value of these variables to trigger other jobs. So my code looks something like this: node { withCredentials([[$class: 'StringBinding', credentialsId: 'DOCKER_HOST', variable: 'DOCKER_HOST']]) { env.T_RELEASE_VERSION = T_RELEASE_VERSION env.C_RELEASE_VERSION = C_RELEASE_VERSION env.N

Jenkins DSL script - Test Failure - Found multiple extensions which provide method lastCompleted

最后都变了- 提交于 2019-12-10 11:56:15
问题 Trying to create multijobs in Jenkins with DSL scripting. There are multiple jobs in a phase and I want to create a consolidated report for the multijob from downstream jobs. I am using copy artifact to copy the results of downstream jobs to the multijob's target dir. Using selector - lastCompleted() However I am getting this an error saying multiple extensions providing the method and tests are failing. lastCompleted() is apparently present in copyArtifact and multijob plugins where in this

jenkins declarative pipeline set variables derived from parameters

不羁的心 提交于 2019-12-08 15:07:40
问题 I am using a declarative pipeline in a Jenkinsfile but I would like to derive some variables from a parameter. For example given: parameters { choice(name: 'Platform',choices: ['Debian9', 'CentOS7'], description: 'Target OS platform', ) } I would like to add a block like: script { switch(param.Platform) { case "Centos7": def DockerFile = 'src/main/docker/Jenkins-Centos.Dockerfile' def PackageType = 'RPM' def PackageSuffix = '.rpm' break case "Debian9": default: def DockerFile = 'src/main