Reputation: 506
I am testing some Jenkins Pipeline commands for my project and i have having an issue using the when
command.
I am using Jenkins 2.19 and i get an unsupported DSL command error when using this command.
node{
stage('Hello'){
when{
isUnix()
}
echo 'Hello'
}
}
Error:
java.lang.NoSuchMethodError: No such DSL method 'when' found among steps [archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, getContext, git, input, isUnix, library, libraryResource, load, mail, milestone, node, parallel, properties, publishHTML, pwd, readFile, readTrusted, resolveScm, retry, script, sh, sleep, stage, stash, step, svn, timeout, timestamps, tool, unarchive, unstash, waitUntil, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeFile, ws] or symbols [all, always, ant, antFromApache, antOutcome, antTarget, any, apiToken, architecture, archiveArtifacts, artifactManager, batchFile, booleanParam, branch, buildButton, buildDiscarder, caseInsensitive, caseSensitive, choice, choiceParam, clock, cloud, command, configFile, configFileProvider, cron, crumb, defaultView, demand, disableConcurrentBuilds, docker, dockerfile, downloadSettings, downstream, dumb, envVars, environment, expression, file, fileParam, filePath, fingerprint, frameOptions, freeStyle, freeStyleJob, git, github, githubPush, gradle, hyperlink, hyperlinkToModels, installSource, jdk, jdkInstaller, jgit, jgitapache, jnlp, jobDsl, jobName, junit, label, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, legacy, legacySCM, list, local, location, logRotator, loggedInUsersCanDoAnything, masterBuild, maven, maven3Mojos, mavenErrors, mavenMojos, mavenWarnings, modernSCM, msbuild, msbuildError, msbuildWarning, myView, nodeProperties, nonStoredPasswordParam, none, overrideIndexTriggers, paneStatus, parameters, password, pattern, pipeline-model, pipelineTriggers, plainText, plugin, projectNamingStrategy, proxy, queueItemAuthenticator, quietPeriod, run, runParam, schedule, scm, scmRetryCount, search, security, shell, skipDefaultCheckout, skipStagesAfterUnstable, slave, stackTrace, standard, status, string, stringParam, swapSpace, text, textParam, tmpSpace, toolLocation, unsecured, upstream, usernameColonPassword, usernamePassword, viewsTabBar, weather, zfs, zip] or globals [currentBuild, docker, env, params, pipeline, scm]
Is my version of Jenkins not recent enough to support such a command? I haven't found anything related to supported commands being version limited.
Upvotes: 0
Views: 701
Reputation: 1193
The when
command is part of the Declarative Pipeline syntax; it will not work in a Scripted Pipeline.
The rough equivalent in Scripted Pipeline would be:
node {
stage('Hello') {
if (isUnix()) {
echo 'Hello'
}
}
}
Upvotes: 3
Reputation: 349
node{
stage('Hello'){
isUnix()
echo 'Hello'
}
}
The above code should work.
Having said that, there are a lot of differences between Declarative pipeline and Scripted pipeline. One key difference is the syntactical usage. The 'when' and 'isUnix()' command may/do not go hand in hand. For instance, please refer this link to know how to use 'when' command. Moreover, I am not sure whether 'when' command could be used for functions returning the boolean output. 'IsUnix()' always produces boolean output(the default output being true).
Upvotes: -2