我尝试使用共享库通过Jenkinsfile创建Jenkins管道。我通过Web UI创建了一个工作来获取Jenkins文件,这个工作正常。但是,Jenkins似乎无法识别共享库内容。下面是Jenkinsfile和共享库内容以及控制台错误。我仔细检查了Jenkins通用配置(设置了共享库scm)和Pipeline插件安装。不知道还能去哪里。
共享库内容
# var/log.groovy
def call(String name = 'human') {
echo "Hello, ${name}."
}
Jenkinsfile内容
# Jenkinsfile
@Library('jenkinstest') _
node {
log("User!")
}
记录错误
Loading library jenkinstest@master
Attempting to resolve master from remote references...
> /usr/bin/git --version # timeout=10
using GIT_SSH to set credentials Gitlab ssh key
> /usr/bin/git ls-remote -h -t #############/jenkinstest.git # timeout=10
Found match: refs/heads/master revision #############
> /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
Fetching without tags
Fetching upstream changes from git@##############/jenkinstest.git
> /usr/bin/git --version # timeout=10
using GIT_SSH to set credentials Gitlab ssh key
> /usr/bin/git fetch --no-tags --progress git@##############/jenkinstest.git +refs/heads/*:refs/remotes/origin/*
Checking out Revision ############# (master)
> /usr/bin/git config core.sparsecheckout # timeout=10
> /usr/bin/git checkout -f #############
Commit message: "fix on groovy"
> /usr/bin/git rev-list --no-walk ############# # timeout=10
[Pipeline] node
Running on jenkins-node3 in /Users/admin/jenkins-home/workspace/automation-pipeline
[Pipeline] {
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.NoSuchMethodError: No such DSL method 'log' found among steps [acceptGitLabMR, addGitLabMRComment, ansiColor, archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, getContext, git, gitlabBuilds, gitlabCommitStatus, input, isUnix, jiraComment, jiraIssueSelector, jiraSearch, junit, library, libraryResource, load, mail, milestone, node, parallel, powershell, properties, publishHTML, pwd, readFile, readTrusted, resolveScm, retry, script, sh, slackSend, sleep, sshagent, stage, stash, step, svn, task, throttle, timeout, timestamps, tm, tool, unarchive, unstash, updateGitlabCommitStatus, validateDeclarativePipeline, waitUntil, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeFile, ws] or symbols [all, allOf, always, ant, antFromApache, antOutcome, antTarget, any, anyOf, apiToken, architecture, archiveArtifacts, artifactManager, authorizationMatrix, batchFile, bitbucket, booleanParam, branch, buildButton, buildDiscarder, buildParameter, caseInsensitive, caseSensitive, certificate, changelog, changeset, choice, choiceParam, cleanWs, clock, cloud, command, compressBuildLog, configFile, configFileProvider, copyArtifacts, credentials, cron, crumb, defaultView, demand, disableConcurrentBuilds, docker, dockerCert, dockerfile, downloadSettings, downstream, dumb, envVars, environment, expression, file, fileParam, filePath, fingerprint, frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, git, gitLabConnection, github, githubPush, gitlab, gradle, headRegexFilter, headWildcardFilter, hyperlink, hyperlinkToModels, inheriting, inheritingGlobal, installSource, jdk, jdkInstaller, jgit, jgitapache, jnlp, jobName, label, lastCompleted, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, lastSuccessful, latestSavedBuild, legacy, legacySCM, list, local, location, logRotator, loggedInUsersCanDoAnything, masterBuild, maven, maven3Mojos, mavenErrors, mavenMojos, mavenWarnings, modernSCM, myView, node, nodeProperties, nonInheriting, nonStoredPasswordParam, none, not, nunit, overrideIndexTriggers, paneStatus, parameterizedCron, parameters, password, pattern, permalink, pipeline-model, pipelineTriggers, plainText, plugin, pollSCM, projectNamingStrategy, proxy, queueItemAuthenticator, quietPeriod, remotingCLI, run, runParam, schedule, scmRetryCount, search, security, shell, skipDefaultCheckout, skipStagesAfterUnstable, slave, sourceRegexFilter, sourceWildcardFilter, specific, sshUserPrivateKey, stackTrace, standard, status, string, stringParam, swapSpace, text, textParam, tmpSpace, toolLocation, unsecured, upstream, usernameColonPassword, usernamePassword, viewsTabBar, weather, withAnt, workspace, zfs, zip] or globals [currentBuild, docker, env, manager, params, pipeline, scm]
答案 0 :(得分:3)
将git中的var/
文件夹重命名为vars/
。在此文件夹中,您可以存储groovy脚本。
答案 1 :(得分:0)
这应该有效:
@Library('jenkinstest') _
new var.log.call(name)