I have a pipeline in jenkins with maven 3.0.2, that I want to update the version of sonarqube from 6.7 to 8.9. When trying to use the "when" condition in Jenkins (first time I try), I get an error No such DSL method 'when' found among steps. According to lei, some maven plugin is missing, I already tried some but it still doesn't work. Any ideas?
container ("standard") {
try {
stage('mySq') {
when { not {changeRequest()} }
steps {
withSonarQubeEnv(installationName: 'mySqinst', credentialsId: 'myCred')
{ withMaven(maven: env.MAVEN_VERSION, jdk: 'OpenJDK-Latest-JDK11',
globalMavenSettingsConfig: env.MAVEN_GLOBAL_CONFIG) {
//s
sh '''
mvn -Dsonar.login=${SONAR_AUTH_TOKEN} \
-Dsonar.branch.name=${BRANCH_NAME} \
${SONAR_MAVEN_GOAL}
'''
}
}
}
}catch {exception e}
Indeed, your pipeline has a scripted definition (the old one) and it doesn't exist there
when
.You have to migrate it to be declarative. Check this link to see the difference. A basic example is:
If you use a docker container, you need to review how a container runs and use it as an agent. Then goes a set of
stages
, each with a set ofsteps
.You can check your version of Jenkins and see if, inside the job, you have the pipeline syntax option that helps you build steps with the correct syntax
Thank you so much! very useful info. Also, for whoever is reading this question, in Jenkins there is a way to generate the declarative pipeline inside the job.