Jenkins支持的语法命令

时间:2017-03-15 12:40:00

标签: jenkins jenkins-pipeline

我正在为我的项目测试一些Jenkins管道命令,并且使用when命令时遇到了问题。

我正在使用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]

我的詹金斯版本是否不足以支持这样的命令?我还没有发现任何与支持的命令相关的版本限制。

2 个答案:

答案 0 :(得分:3)

when命令是Declarative Pipeline syntax的一部分;它不适用于脚本管道。

Scripted Pipeline中的粗略等价物是:

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

答案 1 :(得分:-2)

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

以上代码应该有效。

话虽如此,Declarative管道和Scripted管道之间存在很多差异。一个关键的区别是语法用法。 '当'和' isUnix()'命令可能/不可以齐头并进。例如,请参考this link了解如何使用'何时使用'命令。而且,我不确定'何时' command可用于返回布尔输出的函数。 ' IsUnix()'总是产生布尔输出(默认输出为true)。