Reputation: 2328
What is the syntax for using the Date Parameter Plugin in a declarative pipeline.
So far I have tried this:
pipeline {
agent {
node {
label 'grange-jenkins-slave'
}
}
options { disableConcurrentBuilds() }
parameters {
date(name: 'EffectiveDate',
dateFormat: 'MMddyyy',
defaultValue: 'LocalDate.now();',
description: 'Effective Date',
trim: true)
file(name:'algo.xlsx', description:'Your algorithm file')
choice(name: 'currency',
choices: ['USD'],
description: 'Select a currency')
}
stages {
stage('genRates') {
steps {
script {
echo "test"
}
}
}
}
}
The error I get is WorkflowScript: 11: Invalid parameter type "date". Valid parameter types: [booleanParam, choice, credentials, file, text, password, run, string] @ line 11, column 3.
Upvotes: 5
Views: 9053
Reputation: 11
I did not use date parameter plugin as I didn't find any example how to use it. I resolved this in a different way.
import java.text.SimpleDateFormat
def sdf = new SimpleDateFormat("yyyyMMdd")
def dateDefaultValue = sdf.format(new Date())
pipeline {
parameters {
string(name: 'SOMEDATE', defaultValue: "${dateDefaultValue}", description: 'Default value is current date in the format YYYYmmdd', trim: true)
}
.....
.....
}
Upvotes: 1
Reputation: 551
you can define parameter as class DateParameterDefinition.
example:
properties([parameters([
string(name: 'somestring', defaultValue: 'somevalue'),
[$class: 'DateParameterDefinition',
name: 'somedate',
dateFormat: 'yyyyMMdd',
defaultValue: 'LocalDate.now()']
])])
pipeline {
...
}
Upvotes: 2