How to stop Jenkins polling SVN source control? - jenkins

I have a Jenkins server building our project and there's a data section that gets checked out from source control (SVN). I changed it to try to stop it being included in source control polling (poll: false) however I can see changes to the repository are still triggering builds.
Have I got the syntax correct here? I added "poll: false" but it's being ignored.
stage('Data Checkout')
{
dir('E:\\workspace\\data')
{
checkout([
poll: false,
scm: [$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[credentialsId: 'xxx',
depthOption: 'infinity',
ignoreExternalsOption: true,
local: 'local',
remote: "svn://xxx/data"]],
workspaceUpdater: [$class: 'UpdateUpdater']]])
}
}

Related

Trigger a build in pipeline script at SCM Change of a special file

Project Folder is an external in a svn checkout. In this folder is a file, what should be used as trigger for a overnight build. Just on SVN change of this file a build should be triggerd. I used the option with includedRegions, but I reached no success. What could be false?
stage('Checkout AppBuilder Repository'){
steps{
checkout([$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '',
filterChangelog: false,
ignoreDirPropChanges: true,
includedRegions: '.*/Aenderungslisten.vi/.*',
locations: [[cancelProcessOnExternalsFail: false,
credentialsId: "${env.SVN_CRED_ID}",
depthOption: 'infinity',
ignoreExternalsOption: false, local: './AppBuilder',
remote: "${env.APP_BUILDER_URL}"]],
quietOperation: false,
workspaceUpdater: [$class: 'CheckoutUpdater']])
}
}

Jenkins pipeline with userinput extendedChoice returns the values with [ ] at the beginning and end

I added the below to the pipeline so while the pipeline is running - at some stage I want the user to choose from the parameters but the output returns with parentheses at beginning and end.
def envs = input(id: 'Upgarde', message: 'On which customer do you want to apply the upgrade?', submitter: 'admin', ok: 'Submit', parameters: [extendedChoice(defaultValue: env.ENV.split().toString(), description: '', descriptionPropertyValue: env.ENV.split().toString(), multiSelectDelimiter: '', name: 'Customers to upgrade', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_SELECT', value: env.ENV.split().toString())]).split(',')
Screenshot from the Jenkins UI:
enter image description here
Fixed by added .replace("[", "").replace("]", "")

How to set default value Jenkins active choice parameter as a script

I have a Jenkins pipeline That has parameters defined via active choice parameter,
defining a default value is done by:
defaultValue: '',
you can put a string there or leave it empty which will give you the default result of the groovyScript.
I am trying to change the default parameter using a script so it will take the value using a groovy script.
This is the snippet of the relevant part of the pipeline:
parameters([
extendedChoice(
bindings: '',
defaultValue: '',
groovyClasspath: '',
groovyScript:"""
def proc = ["bash","-c","/usr/local/bin/aws s3 ls s3://Spark-Jenkins-Clusters/"].execute() | ["bash","-c","cut -c32-"].execute()
proc.waitForOrKill(10000)
return proc.text.tokenize()
""",
multiSelectDelimiter: ',',
name: 'Choose_Cluster',
description: 'This parameter is nice',
quoteValue: false,
saveJSONParameterToFile: false,
type: 'PT_SINGLE_SELECT',
visibleItemCount: 5
),
So The way to do that is to use "defaultGroovyScript",
I didn't find it in the documentation I just saw an option in the UI and tried it and luckily it worked:
This is what I finally did:
parameters([
extendedChoice(
bindings: '',
defaultGroovyScript: """
def proc = ["bash","-c","/usr/local/bin/aws s3 ls s3://Spark-Jenkins-Clusters/"].execute() | \
["bash","-c","sort"].execute() | \
["bash","-c","sed 's/PRE//g'"].execute() | \
["bash","-c","grep main"].execute() | \
["bash","-c","tail -n 1"].execute() | \
["bash","-c","tr -d '/'"].execute()
proc.waitForOrKill(10000)
return proc.text.tokenize().reverse()
""",
groovyClasspath: '',
groovyScript:"""
def proc = ["bash","-c","/usr/local/bin/aws s3 ls s3://Spark-Jenkins-Clusters/"].execute() | ["bash","-c","cut -c32-"].execute()
proc.waitForOrKill(10000)
return proc.text.tokenize()
""",
multiSelectDelimiter: ',',
name: 'Choose_Cluster',
description: 'This parameter is nice',
quoteValue: false,
saveJSONParameterToFile: false,
type: 'PT_SINGLE_SELECT',
visibleItemCount: 5
),

Is it possible to have a Jenkins parameter's name with spaces in it?

I'm trying to make my Jenkins UI more clean.
My Jenkins file calls a function which in turn runs the following:
properties ([
[$class: 'GitLabConnectionProperty', gitLabConnection: 'GitlabConnection'],
[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
[$class: 'BooleanParameterDefinition', defaultValue: false, description: '', name: 'activateInTest'],
[$class: 'ChoiceParameterDefinition', choices: 'false\ntrue\n', description: 'If running newBuild, skip unit tests', name: 'skipUnitTests']
]]
])
Currently, I can access these parameters like this:
if(activateInTest == 'true') {
//Do something
}
After going through other docs and examples. It looked as if I could also access parameters by doing something like params.activateInTest, which did not work. I also tried doing something like params["activateInTest"], but that didn't work either.
The reason I want to access it this way params["..."], is because I would like to have the name of my parameter be "Activate in Test" rather than "activateInTest".
In this example I see the person does use "BooleanParameterDefinition" with spaces in the name. But I can't seem to figure out how to use spaces in the name. Having spaces in the name is my only goal here.
yes, its possible, just use following notation:
${params['Name with space']}
tested on old Jenkins: 2.149
Indeed it is possible, user "string reference" to access it, i.e. params."Activate in Test"
For example:
properties([parameters([
string(name: 'Activate in Test', defaultValue: 'default value')
])])
echo params."Activate in Test"
In Java and Groovy space in a variable does not support! and it's not recommended but Jenkins supports it with 'String referencing'
But If you want to decorate the parameter Display Name it would be something like this
Jenkins Declarative Pipeline
pipeline {
agent any
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
text(name: 'BIOGRAPHY', defaultValue: '', description: 'Enter some information about the person')
booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')
choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')
password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'Enter a password')
}
stages {
stage('Example') {
steps {
echo "Hello ${params.PERSON}"
echo "Biography: ${params.BIOGRAPHY}"
echo "Toggle: ${params.TOGGLE}"
echo "Choice: ${params.CHOICE}"
echo "Password: ${params.PASSWORD}"
}
}
}
}
Scripted Pipeline
node {
properties(
[
parameters(
[string(defaultValue: '/data', name: 'Directory', description: "Directort Path"),
string(defaultValue: 'Dev', name: 'DEPLOY_ENV', description: "Deploy Environment")
]
)
]
)
stage('debug') {
echo "${params}"
}
}

SCM polling with includedRegions in Jenkins pipeline job

I am using GitLab. Given multiple directories, e.g. folder1, folder2, folder3. I would like the job run only if there is any changes under folder1 only. Does anyone able to get includedRegions to work in Jenkins pipeline job.
checkout(
[
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'PathRestriction', excludedRegions: '', includedRegions: 'folder1/.*']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'user', url: 'ssh://something/experiment.git']]
]
)
If you use a pipeline the checkout step performs after the build was launched.
The only way to manage this is to check the changeset with the groovy and skip the build if there were no changes at the included directory.
I managed to get it working. Since the checkout will be used across projects in our Jenkins, I wrote shared libraries to make it handy to use.
Example: strToSparseCheckout.groovy
#!/usr/bin/env groovy
import hudson.plugins.git.extensions.impl.SparseCheckoutPath
def call(paths) {
def list = paths.split('\n')
def sparsePaths = []
def isDefaultAdded = false
list.each {
def path = it - '/.*'
def sparsePath = new SparseCheckoutPath(path)
sparsePaths.push(sparsePath)
}
return sparsePaths
}
Example: sparseCheckout.groovy
#!/usr/bin/env groovy
def call(Map namedargs) {
checkout(
[
$class: 'GitSCM',
branches: [[name: "${namedargs.branch}"]],
extensions: [
[$class: 'LocalBranch', localBranch: '**'],
[$class: 'RelativeTargetDirectory', relativeTargetDir: "${namedargs.target_dir}"],
[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: strToSparseCheckout("${namedargs.included_regions}")],
[$class: 'PathRestriction', excludedRegions: """${namedargs.excluded_regions}""", includedRegions: """${namedargs.included_regions}"""]
],
userRemoteConfigs: [[credentialsId: 'user', url: "${namedargs.url}"]]
]
)
}
In the pipeline, we can call the sparseCheckout shared library.
pipeline {
stage('Checkout') {
sparseCheckout(
[
url: 'ssh://path.to.git/something.git',
branch: 'refs/heads/master',
target_dir: 'something',
excluded_regions: "${params.excluded_regions}",
included_regions: "${params.included_regions}"
]
)
}
}

Resources