jenkinsci / jenkinsci/kubernetes-plugin
[JENKINS-49759] Can't create temp file in Kubernetes Plugin Pipeline
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 1.3k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 3
Description
We are having an issue where we can not create a temp file in a build pipeline within a PodTemplate. Oddly inserting a random 'sh' command before the creation of the temp file solved the problem. Here is the code that fails:
�import hudson.FilePath;
import jenkins.model.Jenkins;def label = "mynode"
podTemplate(
label: label,
nodeSelector: "kops.k8s.io/instancegroup=jenkins-workers",
containers: [containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.9.3', command: 'cat', ttyEnabled: true)]) {node(label) {
container("kubectl") {
def workspace = new FilePath(Jenkins.getInstance().getComputer(env.NODE_NAME).getChannel(), env.WORKSPACE);
workspace.createTempFile("test", ".txt")
sh "ls -al"
}
}
}
The full log is attached, but essentially we get the following exception:
Caused: java.io.IOException: Failed to create a temp file on /home/jenkins/workspace/folder/test-job
at hudson.FilePath.createTempFile(FilePath.java:1330)
Oddly, if we add a "sh" command before the creation of the temp file the job succeeds. The following code works:
�import hudson.FilePath;
import jenkins.model.Jenkins;def label = "mynode"
podTemplate(
label: label,
nodeSelector: "kops.k8s.io/instancegroup=jenkins-workers",
containers: [containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.9.3', command: 'cat', ttyEnabled: true)]) {node(label) {
container("kubectl") {
sh "ls -al" // This added code somehow makes this pipeline succeed.
def workspace = new FilePath(Jenkins.getInstance().getComputer(env.NODE_NAME).getChannel(), env.WORKSPACE);
workspace.createTempFile("test", ".txt")
sh "ls -al"
}
}
}
It does not seem to matter what the "sh" command before the temp file creation is. We have used "pwd", "echo $HOME", etc. and they all have the same effect of making the pipeline work. Of course both sh "ls -al" commands were put in there as debugging steps, and it just so happened that the first one accidentally made the pipeline work.
---
Originally reported by
mmacfadden, imported from: Can't create temp file in Kubernetes Plugin Pipeline
Raw content of original issue
We are having an issue where we can not create a temp file in a build pipeline within a PodTemplate. Oddly inserting a random 'sh' command before the creation of the temp file solved the problem. Here is the code that fails:
�import hudson.FilePath;
import jenkins.model.Jenkins;def label = "mynode"
podTemplate(
label: label,
nodeSelector: "kops.k8s.io/instancegroup=jenkins-workers",
containers: [containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.9.3', command: 'cat', ttyEnabled: true)]) {node(label) {
container("kubectl") {
def workspace = new FilePath(Jenkins.getInstance().getComputer(env.NODE_NAME).getChannel(), env.WORKSPACE);
workspace.createTempFile("test", ".txt")
sh "ls -al"
}
}
}
The full log is attached, but essentially we get the following exception:
Caused: java.io.IOException: Failed to create a temp file on /home/jenkins/workspace/folder/test-job
at hudson.FilePath.createTempFile(FilePath.java:1330)Oddly, if we add a "sh" command before the creation of the temp file the job succeeds. The following code works:
�import hudson.FilePath;
import jenkins.model.Jenkins;def label = "mynode"
podTemplate(
label: label,
nodeSelector: "kops.k8s.io/instancegroup=jenkins-workers",
containers: [containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.9.3', command: 'cat', ttyEnabled: true)]) {node(label) {
container("kubectl") {
sh "ls -al" // This added code somehow makes this pipeline succeed.
def workspace = new FilePath(Jenkins.getInstance().getComputer(env.NODE_NAME).getChannel(), env.WORKSPACE);
workspace.createTempFile("test", ".txt")
sh "ls -al"
}
}
}It does not seem to matter what the "sh" command before the temp file creation is. We have used "pwd", "echo $HOME", etc. and they all have the same effect of making the pipeline work. Of course both sh "ls -al" commands were put in there as debugging steps, and it just so happened that the first one accidentally made the pipeline work.
environment
```
Kuberetes 1.8
Jenkins 2.107
Kubernetes Plugin: 1.2.1
Java Version: 1.8.0_151
Jenkins Master running in Docker Container in k8s
```
1 attachment
- [failure.log](https://issues.jenkins.io/secure/attachment/41603/failure.log)
Contributor guide
Research direction
Start by reproducing the provided PodTemplate pipeline with Kubernetes 1.8, Jenkins 2.107, and Kubernetes Plugin 1.2.1, using failure.log for the complete trace. Inspect hudson.FilePath.createTempFile at line 1330 and the Kubernetes plugin path around the PodTemplate/container steps. Done means the workspace temp file is created reliably without a preceding sh command.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java, kubernetes
- Domain
- cloud, devops, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100