Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
buildPlugin(jenkinsVersions: [null, '2.60'])
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
<version>1.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>instance-identity</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ public static class Execution extends AbstractSynchronousStepExecution<Void> {
+ "node {\n"
+ " withCredentials([usernamePassword(usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD', credentialsId: '" + credentialsId + "')]) {\n"
+ " semaphore 'basics'\n"
+ " sh '''\n"
+ " set +x\n"
+ " echo curl -u $USERNAME:$PASSWORD server > script.sh\n"
+ " '''\n"
+ " if (isUnix()) {\n"
+ " sh 'echo curl -u $USERNAME:$PASSWORD server > script'\n"
+ " } else {\n"
+ " bat 'echo curl -u %USERNAME%:%PASSWORD% server > script'\n"
+ " }\n"
+ " }\n"
+ "}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
Expand All @@ -157,7 +158,7 @@ public static class Execution extends AbstractSynchronousStepExecution<Void> {
story.j.waitForCompletion(b);
story.j.assertBuildStatusSuccess(b);
story.j.assertLogNotContains(password, b);
FilePath script = story.j.jenkins.getWorkspaceFor(p).child("script.sh");
FilePath script = story.j.jenkins.getWorkspaceFor(p).child("script");
assertTrue(script.exists());
assertEquals("curl -u " + username + ":" + password + " server", script.readToString().trim());
assertEquals(Collections.<String>emptySet(), grep(b.getRootDir(), password));
Expand Down Expand Up @@ -263,7 +264,7 @@ public void widerRequiredContext() throws Exception {
+ "node('myslave') {"
+ " withCredentials([file(variable: 'SECRET', credentialsId: 'creds')]) {\n"
+ " semaphore 'cleanupAfterRestart'\n"
+ " sh 'cp $SECRET key'\n"
+ " if (isUnix()) {sh 'cp $SECRET key'} else {bat 'copy %SECRET% key'}\n"
+ " }\n"
+ "}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
Expand Down Expand Up @@ -333,7 +334,7 @@ private static FilePath tempDir(FilePath ws) {
+ "node {\n"
+ " withCredentials([string(credentialsId: '" + credentialsId + "', variable: 'SECRET')]) {\n"
// forgot set +x, ran /usr/bin/env, etc.
+ " sh 'echo $SECRET > oops'\n"
+ " if (isUnix()) {sh 'echo $SECRET > oops'} else {bat 'echo %SECRET% > oops'}\n"
+ " }\n"
+ "}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0).get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,16 @@ public void basics() throws Exception {
.<MultiBinding<?>> singletonList(binding)));
if (Functions.isWindows()) {
p.getBuildersList().add(new BatchFile(
"@echo off\n"
+ "echo | set /p=\"%alias%/%password%/\" > secrets.txt\n"
+ "IF EXIST %keystore% (\n"
+ "echo | set /p=\"exists\" >> secrets.txt\n"
+ ") ELSE (\n"
+ "echo | set /p=\"missing\" >> secrets.txt\n"
+ ")"));
"echo | set /p=\"%alias%/%password%/\" > secrets.txt\r\n"
+ "IF EXIST %keystore% (\r\n"
+ "echo | set /p=\"exists\" >> secrets.txt\r\n"
+ ") ELSE (\r\n"
+ "echo | set /p=\"missing\" >> secrets.txt\r\n"
+ ")\r\n"
+ "exit 0"));
} else {
p.getBuildersList().add(new Shell(
"set +x\n"
+ "printf $alias/$password/ > secrets.txt\n"
"printf $alias/$password/ > secrets.txt\n"
+ "if [ -f \"$keystore\" ]\n"
+ "then\n"
+ "printf exists >> secrets.txt\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.domains.Domain;
import hudson.Functions;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Item;
import hudson.tasks.BatchFile;
import hudson.tasks.Shell;
import hudson.util.Secret;
import org.jenkinsci.plugins.credentialsbinding.MultiBinding;
Expand Down Expand Up @@ -67,8 +69,8 @@ public class SecretBuildWrapperTest {
FreeStyleProject f = r.createFreeStyleProject();

f.setConcurrentBuild(true);
f.getBuildersList().add(new Shell("echo $PASS_1"));
f.getBuildersList().add(new Shell("echo $PASS_2"));
f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_1%") : new Shell("echo $PASS_1"));
f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_2%") : new Shell("echo $PASS_2"));
f.getBuildWrappersList().add(wrapper);

r.configRoundtrip((Item)f);
Expand All @@ -86,7 +88,7 @@ public class SecretBuildWrapperTest {
FreeStyleProject f = r.createFreeStyleProject();

f.setConcurrentBuild(true);
f.getBuildersList().add(new Shell("echo PASSES"));
f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo PASSES") : new Shell("echo PASSES"));
f.getBuildWrappersList().add(wrapper);

r.configRoundtrip((Item)f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.Functions;
import hudson.Util;
import hudson.model.Fingerprint;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.remoting.Future;
import hudson.tasks.BatchFile;
import hudson.tasks.Shell;
import java.util.Collections;
import java.util.List;
Expand All @@ -67,7 +69,7 @@ public class UsernamePasswordBindingTest {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.<Binding<?>>singletonList(new UsernamePasswordBinding("AUTH", c.getId()))));
p.getBuildersList().add(new Shell("set +x\necho $AUTH > auth.txt"));
p.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %AUTH% > auth.txt") : new Shell("echo $AUTH > auth.txt"));
r.configRoundtrip(p);
SecretBuildWrapper wrapper = p.getBuildWrappersList().get(SecretBuildWrapper.class);
assertNotNull(wrapper);
Expand Down