2017-03-15 38 views
0

我正在为我的项目测试一些Jenkins管道命令,并且使用when命令发生问题。Jenkins支持的语法命令

我正在使用Jenkins 2.19,并且在使用此命令时出现不受支持的DSL命令错误。

node{ 
    stage('Hello'){ 
    when{ 
     isUnix() 
    } 
    echo 'Hello' 
    } 
} 

错误:

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] 

是我詹金斯不够最近的版本来支持这样的命令?我还没有发现与受版本限制的支持命令相关的任何内容。

回答

3

when命令是Declarative Pipeline syntax的一部分;它不会在脚本管道中工作。

大致相当于在脚本管道将是:

node { 
    stage('Hello') { 
    if (isUnix()) { 
     echo 'Hello' 
    } 
    } 
} 
-2
node{ 
    stage('Hello'){ 
      isUnix() 
      echo 'Hello' 
       } 
    } 

上面的代码应该工作。尽管如此,Declarative pipeline和Scripted pipeline之间还是有很多不同之处的。一个关键的区别是语法用法。 'when'和'isUnix()'命令可能并不完全一致。例如,请参阅this link以了解如何使用'when'命令。此外,我不确定'when'命令是否可用于返回布尔输出的函数。 'IsUnix()'总是产生布尔输出(默认输出为true)。

+0

请添加更多详细信息,说明“上述代码应该如何工作”。 –

+0

'如'如克里斯托弗在他的评论中提到的那样'使用'。他所指的是声明管道。你正在使用的那个看起来像脚本管道。此外,我不确定'when'命令是否可用于返回布尔输出的函数。 'IsUnix()'总是产生布尔输出(默认为true)。 – Karthick

+0

说明很好,但请编辑您的答案,并直接将答案添加到答案中,而不是评论;) – Pom12