jenkinsfile-runner
jenkinsfile-runner copied to clipboard
Unable to add shared library
My Dockerfile:
FROM jenkins/jenkinsfile-runner
COPY casc.yaml /usr/share/jenkins/ref/casc/casc.yaml
ENV CASC_JENKINS_CONFIG /usr/share/jenkins/ref/casc/casc.yaml
casc:
jenkins:
mode: NORMAL
numExecutors: 1
labelString: "linux"
scmCheckoutRetryCount: 0
myViewsTabBar: "standard"
viewsTabBar: "standard"
globalNodeProperties:
- envVars:
env:
- key: TestKey
value: TestValue
tool:
git:
installations:
- home: "git"
name: "Default"
unclassified:
globalLibraries:
libraries:
- defaultVersion: "master"
name: "jenkins-std-lib"
implicit: false
retriever:
modernSCM:
scm:
git:
remote: "https://github.com/DontShaveTheYak/jenkins-std-lib.git"
My Jenkinsfile:
@Library('jenkins-std-lib')
import org.dsty.bash.BashClient
node(){
bash = new BashClient(this)
def result = bash.ignoreErrors('fakecommand', consoleOutput=false)
print(result.stdErr)
}
When I run it I get an error about git
: Caused: java.io.IOException: Cannot run program "git": error=2, No such file or directory
I have tried with and without the tool:
in the CASC config. I see git
in the poml for the vanilla package but It still doesn't seen to work.
shadycuz-> docker run --rm -v $PWD:/workspace myrunner
2021-03-07 11:05:39.135+0000 [id=36] WARNING i.j.p.casc.BaseConfigurator#createAttribute: Can't handle class jenkins.plugins.git.GitSCMSource#owner: type is abstract but not Describable.
2021-03-07 11:05:39.526+0000 [id=36] WARNING i.j.p.casc.BaseConfigurator#createAttribute: Can't handle class jenkins.plugins.git.GitSCMSource#owner: type is abstract but not Describable.
2021-03-07 11:05:39.642+0000 [id=1] WARNING j.branch.WorkspaceLocatorImpl#getWorkspaceRoot: JENKINS-2111 path sanitization ineffective when using legacy Workspace Root Directory ‘/build’; switch to ‘${JENKINS_HOME}/workspace/${ITEM_FULL_NAME}’ as in JENKINS-8446 / JENKINS-21942
Started
Resume disabled by user, switching to high-performance, low-durability mode.
Loading library jenkins-std-lib@master
Attempting to resolve master from remote references...
> git --version # timeout=10
> git --version # timeout=10
> git ls-remote https://github.com/DontShaveTheYak/jenkins-std-lib.git # timeout=10
ERROR: Checkout failed
java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
Caused: java.io.IOException: Cannot run program "git": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:252)
at hudson.Proc$LocalProc.<init>(Proc.java:221)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:996)
at hudson.Launcher$ProcStarter.start(Launcher.java:508)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2443)
Caused: hudson.plugins.git.GitException: Error performing git command: git ls-remote https://github.com/DontShaveTheYak/jenkins-std-lib.git
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2457)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2051)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1951)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1942)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRemoteReferences(CliGitAPIImpl.java:3381)
at jenkins.plugins.git.AbstractGitSCMSource.retrieve(AbstractGitSCMSource.java:838)
at jenkins.scm.api.SCMSource.fetch(SCMSource.java:636)
at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.lambda$retrieve$0(SCMSourceRetriever.java:92)
at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.retrySCMOperation(SCMSourceRetriever.java:107)
at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.retrieve(SCMSourceRetriever.java:92)
at org.jenkinsci.plugins.workflow.libs.LibraryAdder.retrieve(LibraryAdder.java:157)
at org.jenkinsci.plugins.workflow.libs.LibraryAdder.add(LibraryAdder.java:138)
at org.jenkinsci.plugins.workflow.libs.LibraryDecorator$1.call(LibraryDecorator.java:125)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1065)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
ERROR: Maximum checkout retry attempts reached, aborting
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: Loading libraries failed
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
I was finally able to get this to work by building this https://github.com/jenkinsci/ci.jenkins.io-runner/ and adding
unclassified:
globalLibraries:
libraries:
- defaultVersion: "master"
name: "jenkins-std-lib"
implicit: false
retriever:
modernSCM:
scm:
git:
remote: "https://github.com/DontShaveTheYak/jenkins-std-lib.git"
to its jenkins.yaml.
The only downside is that the resulting image is big and SLOW. Seems like it shouldn't be that hard to add a shared library to jenkinsfile-runner
.
I also noticed that the beginning of the output from these two dockers are very different and I can't explain it.
shadycuz-> docker run --rm -v $PWD:/workspace iorunner
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/app/repo/org/slf4j/slf4j-simple/1.7.2/slf4j-simple-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/app/repo/org/slf4j/slf4j-jdk14/1.7.26/slf4j-jdk14-1.7.26.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[main] INFO org.eclipse.jetty.util.log - Logging initialized @805ms to org.eclipse.jetty.util.log.Slf4jLog
[Executing main] INFO org.eclipse.jetty.server.Server - jetty-9.4.32.v20200930; built: 2020-09-30T16:16:37.804Z; git: de97d26f7bd222a0e16831e353d702a7a422f711; jvm 1.8.0_262-b10
[Executing main] INFO org.eclipse.jetty.webapp.StandardDescriptorProcessor - NO JSP Support for /jenkins, did not find org.eclipse.jetty.jsp.JettyJspServlet
[Executing main] INFO org.eclipse.jetty.server.session - DefaultSessionIdManager workerName=node0
[Executing main] INFO org.eclipse.jetty.server.session - No SessionScavenger set, using defaults
[Executing main] INFO org.eclipse.jetty.server.session - node0 Scavenging every 600000ms
[Executing main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.w.WebAppContext@68d279ec{/jenkins,file:///app/jenkins/,AVAILABLE}{/app/jenkins}
[Executing main] INFO org.eclipse.jetty.server.Server - Started @1567ms
done
2021-03-10 07:24:39.567+0000 [id=34] WARNING i.j.p.casc.BaseConfigurator#createAttribute: Can't handle class jenkins.plugins.git.GitSCMSource#owner: type is abstract but not Describable.
Strange, it should work... Maybe there was an issue in the image build. Will check later.
It is also possible to use JGit client as a workaround (advanced option in the SCM config)
@oleg-nenashev Tomorrow I will retry it again from scratch to make sure I didn't do anything wrong. I will also try an older version to see if that changes things.
@shadycuz did you ever make progress on this? ideally it would work plain vanilla with the configuration that you posted initially
@jcrben I think we can close this. I'm not sure if I ever got it to work. I ended up going back to using a groovy init file. I needed that anyways because I actually look for the library to be a directory inside of the runner first and if not I retrieve it from GitHub. This allows me to test changes to the shared library locally using the runner. The logic for the library is here.