jenkins-pipeline

How to parse JSON with shell scripting?

牧云@^-^@ 提交于 2019-12-12 04:32:13
问题 I have a JSON file from which I need to extract a few parameters and write into another file: devDependencies": { "gulp": "^3.9.1", "gulp-angular-templatecache": "^1.9.1", "gulp-bump": "^1.0.0" } I want to write a file that contains only gulp gulp-angular-templatecache gulp-bump How can I do that using a shell script? 回答1: echo $(grep ^\" file| cut -d\" -f2) But you shouldn't do any more complex json parsing with bash. This is also a hackish solution. 来源: https://stackoverflow.com/questions

Setting a per-node environment variable in a pipeline job

天涯浪子 提交于 2019-12-12 03:43:38
问题 My Jenkins pipeline looks something like this (please forgive small syntax errors): def buildsToDo = "foo bar".tokenize() def buildPlan = [:] for (int i = 0; i < buildsToDo.size(); i ++) { def tag = buildsToDo[i] buildPlan[tag] = { node(tag) { env.ENVVAR = tag stage("build " + tag) { sh 'env' } } } } parallel(buildPlan) My intention is to have one node with ENVVAR=foo and one with ENVVAR=bar . What I actually see is that when the env command runs, ENVVAR=bar is set on both nodes. According to

Jenkins - How to clean / move files under 'builds' directory

丶灬走出姿态 提交于 2019-12-12 03:15:11
问题 I am using Jenkins with Pipeline script. At the end of the script I want to delete/move some contents of Jenkins\jobs\MyMultiBranch\branches\master\builds (i.e. some logs and build.xml) How can it be done using Pipeline? I tried this; bat "del /F \"C:\\Program Files (x86)\\Jenkins\\jobs\\MyMultiBranch\\branches\\master\\builds\\%BUILD_NUMBER%\\build.xml\"" but it's not working, the files are still there. Can anyone help? 回答1: It does make sense that Jenkins would not be able to delete its own

File not unstash in slave machine of jenkins server

守給你的承諾、 提交于 2019-12-12 02:13:55
问题 I used the ubundu as a master machine of jenkins server and configured windows machine as the slave. I tried to stash and unstash a file from master to slave's worksapce but it is not unstashed. node('slave') { node('master'){ stash includes: "file.tgz" name: "master-stash" } unstash "master-stash" bat "ls" } Output: [Pipeline] node Running on master in /var/lib/jenkins/workspace/testing [Pipeline] { [Pipeline] stash Stashed 1 file(s) [Pipeline] } [Pipeline] // node [Pipeline] unstash The

checkoutToSubdirectory not affecting downstream stages

早过忘川 提交于 2019-12-12 01:23:53
问题 I found checkoutToSubdirectory in the Jenkins pipeline docs and in the build console I am seeing output saying Running in /home/ec2-user/workspace/projectDir/subDir but then when the first stage('install/fetch dependencies') { steps { block it gets run in the normal workspace projectDir , not subDir . What else do I need to add to ensure my stages are run in the subDir ? 回答1: The checkoutToSubdirectory don't change the workspace for the build. You can change your workspace by setting

MultiBranch pipeline github webhook

偶尔善良 提交于 2019-12-11 22:28:33
问题 Title pretty much says it all. I've seen these: How to trigger Multibranch Pipeline build with github webhook https://support.cloudbees.com/hc/en-us/articles/224543927-GitHub-webhook-configuration https://support.cloudbees.com/hc/en-us/articles/115003019232-GitHub-Webhook-Pipeline-Multibranch I have a github server setup in jenkins, but cannot choose it in the multibranch source (as one of the links suggests), it asks for credentials but no credentials are in the dropdown. I've also setup a

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

Jenkins RejectedAccessException in whitelisted method

喜你入骨 提交于 2019-12-11 19:35:08
问题 In Jenkins 2.46.3 I'm trying to get the cause of the build (ie whether it was started by a git trigger or a human clicking "build now"). In an answer to another SO question it is suggested that ${currentBuild.buildCauses} has that information, and that the method is whitelisted. But when I try it, i get a RejectedAccessException : org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper

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

Only trigger Jenkins Pipeline job on commit to master

时光毁灭记忆、已成空白 提交于 2019-12-11 18:15:47
问题 I have a Jenkins Pipeline job which is triggered of a github webhook, so on a commit to Github the build gets triggered. However, I only want the build to be triggered when a commit is made to the master branch. Currently any commit triggers a build even if the commit is made on a feature branch. Is there any way to achieve this without resorting to a multibranch job? I can't see any way to filter on branch (for the trigger) in the Jenkins config, the jenkinsfile or in the Github repo's