Docker: Jenkins has failed to create a temporary file in /tmp

Created on 26 Jan 2017  ·  18Comments  ·  Source: jenkinsci/docker

Given a new pull

1/24/2017 10:09:59 PMRunning from: /usr/share/jenkins/jenkins.war
1/24/2017 10:09:59 PMwebroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
1/24/2017 10:09:59 PMException in thread "main" java.io.IOException: Jenkins has failed to create a temporary file in /tmp
1/24/2017 10:09:59 PM   at Main.extractFromJar(Main.java:368)
1/24/2017 10:09:59 PM   at Main._main(Main.java:210)
1/24/2017 10:09:59 PM   at Main.main(Main.java:112)
1/24/2017 10:09:59 PMCaused by: java.io.IOException: Permission denied
1/24/2017 10:09:59 PM   at java.io.UnixFileSystem.createFileExclusively(Native Method)
1/24/2017 10:09:59 PM   at java.io.File.createTempFile(File.java:2024)
1/24/2017 10:09:59 PM   at Main.extractFromJar(Main.java:365)
1/24/2017 10:09:59 PM   ... 2 more

This is over NFS. Here is what the resulting directory looks like:

# ls -lhn JENKINS/
total 8.0K
-rw-r--r-- 1 1000 1000 3.5K Jan 24 22:13 copy_reference_file.log
drwxr-xr-x 2 1000 1000   48 Jan 24 21:47 init.groovy.d
drwxr-xr-x 2 1000 1000 4.0K Jan 24 21:48 plugins

I can also make the tmp dir and mod it to 777:

ls -lhn JENKINS/
total 8.0K
-rw-r--r-- 1 1000 1000 3.6K Jan 24 22:14 copy_reference_file.log
drwxr-xr-x 2 1000 1000   48 Jan 24 21:47 init.groovy.d
drwxr-xr-x 2 1000 1000 4.0K Jan 24 21:48 plugins
drwxrwxrwx 2    0    0    6 Jan 24 22:14 tmp

same result

Most helpful comment

Hi, my resolution was chown jenkins:jenkins -R /var/lib/jenkins/
Thank you.

All 18 comments

so you'll have to give permissions on /tmp or change the tmp dir http://stackoverflow.com/questions/15675783/how-to-change-the-jenkins-tmp-dir-location

I add JENKINS_JAVA_OPTIONS to my environment variables:

  environment:
    - JENKINS_HOME=/var/jenkins_home
    - JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Djava.io.tmpdir=/var/jenkins_home/tmp"

Which is all in a rancher catalog here in case anyone is interested:
https://github.com/WebHostingCoopTeam/whc-catalog

Ok this is getting worse, I sitll have the JENKINS_JAVA_OPTIONS defined, and yet I get Jenkins has failed to create a temporary file in /tmp.

1/30/2017 6:56:22 AMWARN: plugins.sh is deprecated, please switch to install-plugins.sh
1/30/2017 6:56:22 AMAnalyzing: /var/jenkins_home/plugins
1/30/2017 6:56:30 AMDownloading credentials:latest
1/30/2017 6:56:31 AMDownloading git:latest
1/30/2017 6:56:32 AMDownloading git-client:latest
1/30/2017 6:56:33 AMDownloading github:latest
1/30/2017 6:56:34 AMDownloading github-api:latest
1/30/2017 6:56:37 AMDownloading github-oauth:latest
1/30/2017 6:56:38 AMDownloading greenballs:latest
1/30/2017 6:56:38 AMDownloading junit:latest
1/30/2017 6:56:39 AMDownloading plain-credentials:latest
1/30/2017 6:56:39 AMDownloading scm-api:latest
1/30/2017 6:56:40 AMDownloading ssh-credentials:latest
1/30/2017 6:56:40 AMDownloading ssh-slaves:latest
1/30/2017 6:56:41 AMDownloading swarm:latest
1/30/2017 6:56:41 AM---------------------------------------------------
1/30/2017 6:56:41 AMINFO: Successfully installed 13 plugins.
1/30/2017 6:56:41 AMINFO: Please restart the container for changes to take effect!
1/30/2017 6:56:41 AM---------------------------------------------------
1/30/2017 6:56:44 AMRunning from: /usr/share/jenkins/jenkins.war
1/30/2017 6:56:44 AMwebroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
1/30/2017 6:56:44 AMException in thread "main" java.io.IOException: Jenkins has failed to create a temporary file in /tmp
1/30/2017 6:56:44 AM    at Main.extractFromJar(Main.java:368)
1/30/2017 6:56:44 AM    at Main._main(Main.java:210)
1/30/2017 6:56:44 AM    at Main.main(Main.java:112)
1/30/2017 6:56:44 AMCaused by: java.io.IOException: Permission denied
1/30/2017 6:56:44 AM    at java.io.UnixFileSystem.createFileExclusively(Native Method)
1/30/2017 6:56:44 AM    at java.io.File.createTempFile(File.java:2024)
1/30/2017 6:56:44 AM    at Main.extractFromJar(Main.java:365)
1/30/2017 6:56:44 AM    ... 2 more

I've added a few env vars to no effect (still complaining about /tmp)

  environment:
    - JENKINS_HOME=/var/jenkins_home
    - JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Djava.io.tmpdir=/var/jenkins_home/tmp"
    - TMP=/var/jenkins_home/tmp
    - TEMP=/var/jenkins_home/tmp
    - TMPDIR=/var/jenkins_home/tmp

Because you need to use JAVA_OPTS, not JENKINS_JAVA_OPTIONS
https://github.com/jenkinsci/docker#passing-jvm-parameters

changing the environmant variable to JAVA_OPTS give me the same error about /tmp

    - JAVA_OPTS="-Djava.awt.headless=true -Djava.io.tmpdir=/var/jenkins_home/tmp"

gives me the same error:

1/30/2017 7:46:55 AMwebroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
1/30/2017 7:46:55 AMException in thread "main" java.io.IOException: Jenkins has failed to create a temporary file in /tmp
1/30/2017 7:46:55 AM    at Main.extractFromJar(Main.java:368)

given that this is the docker image of jenkins shouldnt that be set by default?

you must be doing something wrong, here is it working

$ docker run --rm -ti -v `pwd`:/tmp:ro jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Exception in thread "main" java.io.IOException: Jenkins has failed to create a temporary file in /tmp
    at Main.extractFromJar(Main.java:368)
    at Main._main(Main.java:210)
    at Main.main(Main.java:112)
Caused by: java.io.IOException: Read-only file system
    at java.io.UnixFileSystem.createFileExclusively(Native Method)
    at java.io.File.createTempFile(File.java:2024)
    at Main.extractFromJar(Main.java:365)
    ... 2 more


$ docker run --rm -e JAVA_OPTS="-Djava.io.tmpdir=/var/jenkins_home" -ti -v `pwd`:/tmp:ro jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Jan 30, 2017 2:29:11 PM Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file /var/jenkins_home/winstone/jenkins.war
Jan 30, 2017 2:29:11 PM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Logging initialized @594ms
Jan 30, 2017 2:29:11 PM winstone.Logger logInternal
INFO: Beginning extraction from war file
Jan 30, 2017 2:29:12 PM org.eclipse.jetty.util.log.JavaUtilLog warn
WARNING: Empty contextPath
Jan 30, 2017 2:29:13 PM org.eclipse.jetty.util.log.JavaUtilLog info

you know I think it's because I did work in /tmp in my Dockerfile, which dirties /tmp somehow, I'm going to change everything to a workdir and see what happens, here is my Dockerfile

Although I'll paste a couple of worrying things, I do have a running jenkins for now, closing

WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war

same error here
$ docker run -ti --name myjenkins -p 8080:8080 -p 50000:50000 myjenkins
May 15, 2017 11:16:19 AM Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war

I have tried all sorts of chown and chmod here, sadly it has not worked.
here is my dockerfile, many things copied from jenkins CI repo
if anybody knows what it is, much appreciated fellows
cheers
Marco

FROM jenkins
#setting up ENV VARS
ENV JENKINS_HOME=/var/jenkins_home
ENV TMP=/var/jenkins_home/tmp
ENV TEMP=/var/jenkins_home/tmp
ENV TMPDIR=/var/jenkins_home/tmp
ENV JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Djava.io.tmpdir=/var/tmp/"

USER root
RUN mkdir /var/log/jenkins
RUN chown -R jenkins:jenkins /var/log/jenkins

RUN mkdir -p /var/jenkins_home/

RUN chown -R jenkins:jenkins /tmp/
RUN chown -R jenkins:jenkins /var/jenkins_home/

#### AUTO BACKUP AND RESTORE
#RUN mkdir -p /var/jenkins_home_restore/
#RUN chown -R jenkins:jenkins /var/jenkins_home_restore/
#ADD backup_20170503_1355.zip /var/jenkins_home_restore/

COPY plugins.sh /usr/local/bin/plugins.sh
COPY install-plugins.sh /usr/local/bin/install-plugins.sh
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh

RUN chmod a+rx /usr/local/bin/plugins.sh
RUN chmod a+rx /usr/local/bin/install-plugins.sh
RUN chmod a+rx /usr/local/bin/jenkins-support
RUN chmod a+rx /usr/local/bin/jenkins.sh

USER jenkins

ENV JAVA_OPTS="-Xmx8192m"
ENV JENKINS_OPTS="--handlerCountStartup=100 --handlerCountMax=300 --logfile=/var/log/jenkins/jenkins.log"

#ADD jenkins.war /usr/share/jenkins/

RUN /usr/local/bin/install-plugins.sh \
ant:1.2 \
antisamy-markupformatter:1.1 `
artifactory:2.4.1 \
backup:1.6.1 \
beaker-builder:1.8 \
BlameSubversion:1.200 \
cobertura:1.9.5

RUN chmod a+rwx /tmp -R
#RUN chmod a+rwx /tmp/winstone/ -R
#RUN chmod a+rwx /tmp/winstone/jenkins.war -R

ENTRYPOINT ["/usr/local/bin/jenkins.sh"]

Facing the issue while extracting the jenkins.war file from command prompt
Unable to delete the winstone file in appdata ...
Need urgent solution for this
C:\Program Files (x86)\Jenkins>java -jar jenkins.war
Running from: C:\Program Files (x86)\Jenkins\jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
←[33mSep 27, 2017 12:19:52 AM Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file C:\Users\selenium\AppData\
Local\Temp\winstone\jenkins.war
←[0mSep 27, 2017 12:19:54 AM org.eclipse.jetty.util.log.Log initialized
INFO: Logging initialized @11332ms to org.eclipse.jetty.util.log.JavaUtilLog
Sep 27, 2017 12:19:55 AM winstone.Logger logInternal
INFO: Beginning extraction from war file
←[33mSep 27, 2017 12:21:23 AM org.eclipse.jetty.server.handler.ContextHandler se
tContextPath
WARNING: Empty contextPath
←[0mSep 27, 2017 12:21:25 AM org.eclipse.jetty.server.Server doStart
INFO: jetty-9.4.z-SNAPSHOT
Sep 27, 2017 12:21:29 AM org.eclipse.jetty.webapp.StandardDescriptorProcessor vi
sitServlet
INFO: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
Sep 27, 2017 12:21:30 AM org.eclipse.jetty.server.session.DefaultSessionIdManage

r doStart

Tried setting up environment variables but not working

I was facing the same problem and I fixed it by removing option '--preferedClassLoader' in environment variable JENKINS_ARGS.

Hoping that it helps

Getting the same problem sine jenkins 2.114

If I start with a clean /var/jenkins_home no problem ... but if I'm upgrading (meaning I use a volume /var/jenkins_home) then upon starting up jenkins 2.114 (my command is ->
docker run --name orchestration -d -p 8080:8080 -p 50000:50000 -v orchestration:/var/jenkins_home jenkins/jenkins <-) I get the :

java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(File.java:2024)
at hudson.util.AtomicFileWriter.(AtomicFileWriter.java:142)
Caused: java.io.IOException: Failed to create a temporary file in /var/jenkins_home
at hudson.util.AtomicFileWriter.(AtomicFileWriter.java:144)
at hudson.util.AtomicFileWriter.(AtomicFileWriter.java:109)
at hudson.util.AtomicFileWriter.(AtomicFileWriter.java:84)
at hudson.util.AtomicFileWriter.(AtomicFileWriter.java:74)
at hudson.XmlFile.write(XmlFile.java:187)
at jenkins.model.Jenkins.save(Jenkins.java:3169)
at jenkins.model.Jenkins.(Jenkins.java:921)
at hudson.model.Hudson.(Hudson.java:85)
at hudson.model.Hudson.(Hudson.java:81)
at hudson.WebAppMain$3.run(WebAppMain.java:233)
Caused: hudson.util.HudsonFailedToLoad
at hudson.WebAppMain$3.run(WebAppMain.java:250)

Hi, my resolution was chown jenkins:jenkins -R /var/lib/jenkins/
Thank you.

@reinaldo-pinto Your suggestion is useful to me,thanks!

@MichaelGreco The trouble is that last I checked Docker Volumes don't support specifying permissions, so you will something like the below in your Dockerfile that uses the upstream Jenkins Docker to build a custom version.

... # Snipped stuff
USER root
RUN chown -R jenkins /var/jenkins_home/tmp
USER jenkins
CMD <whatever is default for container>

If somebody finds it useful at this point of time, for me the issue was fixed after changing the docker image for jenkins.

From docker pull jenkins/jenkins:2.235.5-alpine to docker pull jenkins/jenkins:2.235.5-lts-alpine. BUT sadly, now I am facing a PROXY server issue (Unknown Host while starting) that was not there last week :c

If I found something I will update you too, greets and thanks.
Alan

UPDATE
To fix the Jenkins behind a proxy, in my case I needed to remove all DNS properties from the /etc/docker/daemon.json file.

Hi, my resolution was chown jenkins:jenkins -R /var/lib/jenkins/
Thank you.

I'm using Jenkins in Windows 10 (WSL) and was restricting permissions while updating a file in /var/
updating chown for the folder/files worked perfect for me. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mpv945 picture mpv945  ·  7Comments

jiankafei picture jiankafei  ·  7Comments

greenrobot picture greenrobot  ·  7Comments

fboudra picture fboudra  ·  4Comments

ThStock picture ThStock  ·  8Comments