I've checked the Pipeline syntax page of Jenkins. It's all about the declarative pipeline and I see the syntax.
Can you achieve the same with the declarative Pipeline then with the scripted Pipeline? When I use the generator for the scripted pipeline I see immediately how I can import plugins, use/configure them.
But with the Declarative pipeline I don't see that. I see some main functions and a lot of sh usage.
For example: parameter (and I can add some parameters). But there is some string validation parameter plugin. When I download this plugin I'm able to use it in the Scripted Pipeline etc. But I don't see how I can use this for my Declarative Pipeline.
This I'm facing this use case a lot. Is it possible to use every plugin with a Declarative Pipeline or not? (it seems possible with Scripted Pipeline)
You can read most of the parameter types in the environment
section of your Declarative Pipeline.
pipeline{
agent any
environment {
USER_CRED = credentials('my-user-cred')
USER_NAME = string('my-user-name')
ACTIVE = booleanParam('active')
}
stages {
stage('Example') {
steps {
sh 'echo ${USER_NAME} - ${USER_CRED} - ${ACTIVE}'
}
}
}
}
You also have choice
, file
, password
, run
and text
(and probably other defined in plugins instead of core). Unfortunately the plugin I think you are talking about does not support this use format (as it does not defines a @Symbol
on its implementation .
Using declarative is preferable over scripted, but if you can't do something with declarative, then you can use the script
tag to execute scripted code:
stages {
stage('Stage 1') {
steps {
script {
// scripted code as in non-declarative
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.