I'm trying to create a Jenkins pipeline through Jenkinsfile with Shared Libraries. I created a job through the Web UI to get the Jenkinsfile, which is working ok. However, the shared library content do not seems to be recognizable by Jenkins. Below are the Jenkinsfile and the shared library content and the console error. I double checked the Jenkins general config (where the shared library scm is set) and the Pipeline plugin installation. Don't know where else to go.
Shared Library Content
# var/log.groovy
def call(String name = 'human') {
echo "Hello, ${name}."
}
Jenkinsfile Content
# Jenkinsfile
@Library('jenkinstest') _
node {
log("User!")
}
Log Error
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]
Some of the most common causes for a java.lang.NoSuchMethodError are: If an application calls a method in a third party library, which exists at compile time but not at runtime, it can cause a java.lang.NoSuchMethodError.
Here are the list of variables those are defined and used to be entered by users running pipeline on Jenkins UI. def mailidlist ="$ {mailid}" def bemailidlist="$ {BEmailid}" def pmailidlists = "$ {Pmailidlist}" The same variables mailid/Pmailidlist are used to be given as input values as below:
The only other things I could suggest (bearing in mind I'm not 100% sure) which might be causing your issue above are: It's possible that some of your Pipeline-related plugins (accessible through Manage Jenkins > Manage Plugins) might be disabled or uninstalled. If so, re-activate or re-install them.
So there are two things that need to be checked. In the screenshot below you can see that the library name is the same name given to the function being called in the Jenkinsfile. If you want to change the name you will need to update the Jenkinsfile and in the job config to reflect this change.
Rename your var/
folder in git to vars/
. In this folder you can store your groovy scripts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With