Skip to content

Commit

Permalink
[JENKINS-60517] Add null check for containerWorkingDirFilePath (#671)
Browse files Browse the repository at this point in the history
[JENKINS-60517] Add null check for containerWorkingDirFilePath
  • Loading branch information
Vlatombe authored Jan 6, 2020
2 parents f10b07c + c79c7cc commit 1ac81b8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ public Proc launch(ProcStarter starter) throws IOException {
containerWorkingDirStr = containerWorkingDir.get();
}

if (containerWorkingDir.isPresent() && ! containerWorkingDirFilePath.getRemote().startsWith(containerWorkingDirStr)) {
if (containerWorkingDir.isPresent() &&
containerWorkingDirFilePath != null &&
! containerWorkingDirFilePath.getRemote().startsWith(containerWorkingDirStr)) {
// Container has a custom workingDir, updated the pwd to match container working dir
containerWorkingDirFilePathStr = containerWorkingDirFilePath.getRemote().replaceFirst(
ContainerTemplate.DEFAULT_WORKING_DIR, containerWorkingDirStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,23 @@ public void jnlpWorkingDir() throws Exception {
r.assertBuildStatusSuccess(r.waitForCompletion(b));
}

@Issue("JENKINS-60517")
@Test
public void runInDynamicallyCreatedContainer() throws Exception {
List<PodTemplate> templates = cloud.getTemplates();
while (templates.isEmpty()) {
LOGGER.log(Level.INFO, "Waiting for template to be created");
templates = cloud.getTemplates();
Thread.sleep(1000);
}
assertFalse(templates.isEmpty());
PodTemplate template = templates.get(0);
assertEquals(Integer.MAX_VALUE, template.getInstanceCap());
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("whoami", b);
r.assertLogContains("root", b);
}

@Issue("JENKINS-57256")
@Test
public void basicWindows() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
timeout ([time: 10, unit: 'MINUTES']) {
def label = "jenkins-slave-${UUID.randomUUID().toString()}"
podTemplate(
label: label,
yaml: '''
spec:
containers:
- name: jnlp
''',
containers: [
containerTemplate(name: 'jnlp',
image: 'jenkins/jnlp-slave:latest',
alwaysPullImage: true,
args: '${computer.jnlpmac} ${computer.name}',
),
containerTemplate(
name: 'docker-dind',
image: 'docker:19-dind',
alwaysPullImage: true,
privileged: true,
envVars: [
envVar(key: 'DOCKER_TLS_CERTDIR', value: '')
],
),
containerTemplate(
name: 'docker',
image: 'docker:19',
alwaysPullImage: true,
ttyEnabled: true,
command: 'cat',
envVars: [
envVar(key: 'DOCKER_HOST', value: 'tcp://localhost:2375')
],
),
]
) {
node(label) {
stage('build') {
container('docker') {
sh 'echo "FROM ubuntu:bionic" > Dockerfile'

def tag = "test:${env.BUILD_ID}".toLowerCase()
devTools = docker.build(tag, "--pull -f Dockerfile .")

devTools.inside() {
sh 'whoami'
}
}
}
}
}
}

0 comments on commit 1ac81b8

Please sign in to comment.