jenkins-pipeline

How to configure a Jenkins Pipeline for SonarQube scan

*爱你&永不变心* 提交于 2019-12-12 08:53:44
问题 I am trying to configure a jenkins pipeline for my project, but there is something missing here, if anyone could direct on what I am doing wrong: Below is the pipeline script: node { stage('SonarQube analysis') { // requires SonarQube Scanner 2.8+ def scannerHome = tool 'sonarScanner'; withSonarQubeEnv('SonarQube 6.2') { bat "${scannerHome}/bin/sonar-runner.bat" } } } Below is the Jenkins Sonar Plugin related configurations: Under Manage Jenkins > Configure System : Under Manage Jenkins >

Jenkins : use withCredentials in global environment section

余生颓废 提交于 2019-12-12 08:43:57
问题 I have a Jenkins pipeline with multiple stages that all require the same environment variables, I run this like so: script { withCredentials([usernamePassword(credentialsId: 'COMPOSER_REPO_MAGENTO', passwordVariable: 'MAGE_REPO_PASS', usernameVariable: 'MAGE_REPO_USER')]) { def composerAuth = """{ "http-basic": { "repo.magento.com": { "username": "${MAGE_REPO_USER}", "password": "${MAGE_REPO_PASS}" } } }"""; // do some stuff here that uses composerAuth } } I don't want to have to re-declare

How to use @Library in an imported groovy script in Jenkins declarative pipeline?

亡梦爱人 提交于 2019-12-12 07:18:52
问题 What I have is a following: global shared library created as described here. Nothing special, one script in vars folder called deleteFile.groovy , tried it - works. Library is called myOneLib a pipeline script called firstPipe.groovy @Library('myOneLib') _ def execute(String zCmakeListsPath){ stage('some kind of stage 2') { echo "Hello from stage 1 with " + zCmakeListsPath echo "var attempt ${env.mySrcDir}" } stage('second stage'){ echo "and one from stage 2" echo "param was " +

Jenkins XmlParser reports No such field found for attribute for root node

你离开我真会死。 提交于 2019-12-12 06:48:35
问题 I have a project that has the following XML file (config.xml for a Cordova project) ... <?xml version='1.0' encoding='utf-8'?> <widget android-versionCode="16" id="com.mycomp.myapp" ios-CFBundleVersion="15" version="1.3.0.b4" windows-packageVersion="1.2.6.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <name>My App</name> <description>My app description</description> <author>mycom.com.au</author> .... All I want to do is read the value of the version

'unstash' is not putting anything in the next step of jenkins pipeline

只愿长相守 提交于 2019-12-12 06:41:17
问题 I'm trying to setup Jenkins pipeline that compiles some node/grunt stuff, makes and RPM out of this and upload that RPM to desired repo. Somehow i have difficulties passing files between steps. So in the 'RPM upload stage' generated RPM is not visible and cannot be uploaded. pipeline { agent none stages { stage('Checkout') { agent { label 'master' } steps { checkout(...) } } stage('Build') { agent { docker { image 'custome-nodejs:4' reuseNode true } } steps { sh 'npm install' sh "./build.sh

Creating XML file using StreamingMarkupBuilder() in Jenkins

时光怂恿深爱的人放手 提交于 2019-12-12 05:14:29
问题 i have a groovy method that now creates XML files. I have verified it using the groovyConsole. But if i use this snippet in my jenkinsfile, the XML file is not seen to be created in the workspace, although the job completes successfully. Question: how do i make sure that the XML file is generated in the workspace? I will be using this XML for subsequent stages in the jenkinsfile Here is how the jenkinsfile looks like: import groovy.xml.* node('master') { deleteDir() stage('Checkout') { //

Groovy: regex to filter out “Key:Value” pair and store in an array

牧云@^-^@ 提交于 2019-12-12 04:34:23
问题 I am writing a GROOVY script for a Jenkinsfile to do following: Step-1: read the input file info_file.txt . Contents of info file are as under: sh> cat info_file.txt CHIP_DETAILS:1234-A0;1456-B1;2456-B0;3436-D0;4467-C0 Step-2: Store the CHIP_DETAILS in an array after removing the suffix -A0,-B1 etc.. for example: Integer[] testArray = ["1234", "1456", "2456" , "3436" , "4467"] Step-3: print the elements of the array sequentially. For example: testArray.each { println "chip num is ${it}" } I

How to simplify repeated build job syntax?

雨燕双飞 提交于 2019-12-12 04:33:15
问题 I've the following Groovy script: node { stage('Testing') { build job: 'Test', parameters: [string(name: 'Name', value: 'Foo'), string(name: 'Param1', value: Param1), string(name: 'Param2', value: Param2), string(name: 'Param3', value: Param3), string(name: 'Param4', value: Param4), string(name: 'Param5', value: Param5)], quietPeriod: 2, wait: false build job: 'Test', parameters: [string(name: 'Name', value: 'Bar'), string(name: 'Param1', value: Param1), string(name: 'Param2', value: Param2),

Jenkins pipeline MissingMethodException: No signature of method:

天涯浪子 提交于 2019-12-12 04:32:45
问题 I wrote a function to insert inject a variable through the EnvInj-plugin. Following script I used: import hudson.model.* import static hudson.model.Cause.RemoteCause @com.cloudbees.groovy.cps.NonCPS def call(currentBuild) { def ipaddress="" for (CauseAction action : currentBuild.getActions(CauseAction.class)) { for (Cause cause : action.getCauses()) { if(cause instanceof RemoteCause){ ipaddress=cause.addr break; } } } return ["ip":ipaddress] } When I put it the the folder $JENKINS_HOME

How can you pass same parameters to different builds without redundant code in Jenkins Pipeline

牧云@^-^@ 提交于 2019-12-12 04:32:26
问题 How can you pass same parameters to different builds without redundant code in Jenkins Pipeline groovy. I don't want to repeat the parameters. node('master') { parallel( "stream 1(X)" : { stage('X') { build 'Job1', parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')] } }, "stream 2 (Y)" : { stage('Y') { build 'Job2', parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')] } } ) } 回答1: It is pretty easy : just