jenkins-pipeline

How to do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

戏子无情 提交于 2019-12-17 04:11:45
问题 I have something like this on a Jenkinsfile (Groovy) and I want to record the stdout and the exit code in a variable in order to use the information later. sh "ls -l" How can I do this, especially as it seems that you cannot really run any kind of groovy code inside the Jenkinsfile ? 回答1: The latest version of the pipeline sh step allows you to do the following; // Git committer email GIT_COMMIT_EMAIL = sh ( script: 'git --no-pager show -s --format=\'%ae\'', returnStdout: true ).trim() echo

sonarqube url connection refused for Quality Gate using Jenkins Pipeline

旧街凉风 提交于 2019-12-14 04:03:07
问题 After a good 2 days trying to get Jenkins pipelines to work I've hit an issue in the Quality Gate section I'm unable to resolve. Both Jenkins and SonarQube are on the same server in our network (say 192.168.0.6) Sonarqube can be accessed from this server using localhost:9000 and on my dev computer I've added sonar.ecl to the hosts file pointing to 192.168.0.6 Jenkins is accessed with 192.168.0.6:8080 on my dev box and localhost:8080 from the netwrok server. Both servers are running and can be

aws key and scret working on aws cli but not working on jenkins

丶灬走出姿态 提交于 2019-12-14 03:58:59
问题 I am trying to run python script which has code to access s3 using boto3 sdk. I have created default profile in my windows machine. aws cli commands are working fine in window cmd to access s3 bucket. python script is also working fine in when launched manually in window cmd I am trying to automate it through jenkins. It is failing and complaining about Invalid token. For testing purpose i ran following command in jenkins job. aws sts get-caller-identity --debug ClientError: An error occurred

How to use Groovy template engine when template name is a variable?

被刻印的时光 ゝ 提交于 2019-12-14 03:49:16
问题 I am trying to find a way to make use of a groovy variable in stead of using a hardcoded template name Current code looks like: '${SCRIPT, template="groovy-html.template"}' and I tried to use nested variable expansion but I still got an error. Example: def body = '''${SCRIPT, template="${template}"}''' Groovy Template file [${template}] was not found in $JENKINS_HOME/email-templates. Generated using text.jelly template. My call can be seen at https://github.com/pycontribs/powertape/blob

Jenkins pipeline exception java.io.NotSerializableException: hudson.model.FreeStyleProject

只谈情不闲聊 提交于 2019-12-14 03:04:39
问题 I create Job pipeline, and I try get all jobs which matches regexp, and after parallel start. I get exception: java.io.NotSerializableException: hudson.model.FreeStyleProject Jenkins v 2.5 node { stage('deploy') { def branches = [:] def theJobs = Jenkins.instance.getAllItems(Job); for(int i = 0; i < theJobs.size; i++) { def jobName= theJobs[i].getName(); if( jobName =~ /server\-[0-9][0-9]\..*/) { branches[i] = { build job : "${jobName}", parameters: [[$class: 'StringParameterValue', name:

If else statement not working properly in Jenkins pipeline script (groovy)

家住魔仙堡 提交于 2019-12-14 03:00:52
问题 I have the pipeline script (groovy) where i m trying to use if and else condition but its not behaving normally. Seems it always returns false. Here is my sample (snip of) pipeline script: def branch_exists_in_node = 1 def branch_exists_in_common = 0 def branch_exists_in_extra = 0 if(branch_exists_in_node == 1) { NODE_BRANCH = env.BRANCH_NAME }else { NODE_BRANCH = "master"; } if(branch_exists_in_common == 1) { COMMON_BRANCH = env.BRANCH_NAME }else { COMMON_BRANCH = "master" } But here it

Jenkins Text finder Plugin, How can I use this plugin with jenkinsfile?

送分小仙女□ 提交于 2019-12-14 01:28:56
问题 I am trying write a jenkinsfile using Text Finder plugin, but I don't know exactly how it works. Here's my code: pipeline { agent { label { label "master" } } stages { stage('CHECKOUT') { steps{ script{ echo "##[1 / 4] ERROR" } publishers { textFinder("*ERROR*", '', true, false, true) } } } } } 回答1: As @mghicks already mentions, not every plugin supports Jenkins pipelines. In this case the Text Finder plugin is not supporting it. You can for example write your own groovy function for it: For

Jenkinsfile pipeline construct JSON object and write to file

情到浓时终转凉″ 提交于 2019-12-14 01:23:38
问题 I would like to construct a JSON object and write the content to file. Originally I was inspired by this and tried: def data = [ a:"test: ${myVar}" ] writeJSON(file: 'message1.json', json: data) But this failed with: Could not instantiate {file=message1.json, json={a=test}} for WriteJSONStep(file: String, json: JSON{}, pretty?: int): java.lang.UnsupportedOperationException: must specify $class with an implementation of interface net.sf.json.JSON So next I tried: def data = readJSON text: '{}'

Unversioned files due to “?” folder automatically generated when compiling the git repo in a jenkins pipeline compiled in docker

☆樱花仙子☆ 提交于 2019-12-13 22:43:24
问题 I am configuring Continuous Delivery with gradle using the gradle release plugin. This was working quite well using Travis CI. I am testing the same CD pipeline with Jenkins pipeline compiling everything in a docker container (gradle:4.7.0-jdk8). But I am receiving this error: Execution failed for task ':t_gradle-release-example_release:checkCommitNeeded'. > You have unversioned files: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ?? ?/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Iterating Jenkins groovy map, with multiple sets

醉酒当歌 提交于 2019-12-13 19:09:41
问题 I'd like to ask for help with a a Jenkins groovy pipeline, copied from here: Is it possible to create parallel Jenkins Declarative Pipeline stages in a loop? I'd like for a several sets of vars to be passed in a under a map, for several stages under a parallel run. However, only the last set (square brackets at the bottom of the map) gets registered for my map. When the parallel stage runs, the map iterates successfully, but only with the last set (currently install_Stage(it) ), ignoring