6

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] 
4
  • What happens if you import log underneath the @Library? Commented Jan 10, 2018 at 2:42
  • 3
    What is your git repo setup. You have a subfolder var or vars? In every example they have the folder vars instead of var in which they put their scripts. I think it's really necessary that it's called vars. Commented Jan 10, 2018 at 13:07
  • Attempted both and renaming directory "var" to "vars" was the solution, even though Jenkins documentation uses "var". Thanks a lot @lvthillo Commented Jan 10, 2018 at 15:42
  • 1
    @FelyppeRodrigues No problem. I've written it down as an answer. Please accept it :) Commented Jan 11, 2018 at 17:08

2 Answers 2

7

Rename your var/ folder in git to vars/. In this folder you can store your groovy scripts.

Sign up to request clarification or add additional context in comments.

Comments

-1

This should work:

@Library('jenkinstest') _ new var.log.call(name)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.