Skip to content

Commit

Permalink
Trying to test JENKINS-26051 across restarts but blocked by JENKINS-2…
Browse files Browse the repository at this point in the history
…6137.
  • Loading branch information
jglick committed Jan 12, 2015
1 parent 4fea13c commit 707c1d8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -69,6 +69,13 @@
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>${workflow.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Expand Up @@ -29,10 +29,17 @@
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import hudson.FilePath;
import hudson.model.FileParameterValue;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.RestartableJenkinsRule;
Expand Down Expand Up @@ -64,4 +71,41 @@ public class BindingStepTest {
});
}

@Ignore("TODO JENKINS-26137 java.io.NotSerializableException: hudson.slaves.WorkspaceList$1")
@Test public void cleanupAfterRestart() throws Exception {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
File originalSecret = new File(story.j.jenkins.root, "secret.txt");
FileUtils.write(originalSecret, "s3cr3t");
FileCredentialsImpl c = new FileCredentialsImpl(CredentialsScope.GLOBAL, "creds", "sample", new FileParameterValue.FileItemImpl(originalSecret), null, null);
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), c);
story.j.createSlave("myslave", null, null);
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(""
+ "node('myslave') {"
+ " withCredentials([[$class: 'FileBinding', variable: 'SECRET', credentialsId: 'creds']]) {\n"
+ " semaphore 'cleanupAfterRestart'\n"
+ " sh 'cp $SECRET key'\n"
+ " }\n"
+ "}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("cleanupAfterRestart/1", b);
}
});
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
SemaphoreStep.success("cleanupAfterRestart/1", null);
WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class);
assertNotNull(p);
WorkflowRun b = p.getBuildByNumber(1);
assertNotNull(b);
story.j.assertBuildStatusSuccess(b);
story.j.assertLogNotContains("s3cr3t", b);
FilePath key = story.j.jenkins.getWorkspaceFor(p).child("key");
assertTrue(key.exists());
assertEquals("s3cr3t", key.readToString());
}
});
}

}

0 comments on commit 707c1d8

Please sign in to comment.