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
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<properties>
<revision>1.28</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.249.1</jenkins.version>
<jenkins.version>2.319.1</jenkins.version>
<java.level>8</java.level>
</properties>
<licenses>
Expand Down Expand Up @@ -54,8 +54,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.249.x</artifactId>
<version>984.vb5eaac999a7e</version>
<artifactId>bom-2.319.x</artifactId>
<version>1210.vcd41f6657f03</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand All @@ -65,6 +65,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1087.v16065d268466</version> <!-- TODO until in BOM -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

package org.jenkinsci.plugins.credentialsbinding.impl;

import com.cloudbees.plugins.credentials.Credentials;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.SecretBytes;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;

import hudson.model.Fingerprint;
Expand All @@ -39,6 +41,7 @@
import hudson.Functions;
import hudson.model.Node;
import hudson.model.Result;
import hudson.model.Run;
import hudson.security.FullControlOnceLoggedInAuthorizationStrategy;
import hudson.slaves.DumbSlave;
import hudson.slaves.RetentionStrategy;
Expand All @@ -60,6 +63,7 @@
import org.jenkinsci.plugins.authorizeproject.AuthorizeProjectProperty;
import org.jenkinsci.plugins.authorizeproject.ProjectQueueItemAuthenticator;
import org.jenkinsci.plugins.authorizeproject.strategy.SpecificUsersAuthorizationStrategy;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;
Expand Down Expand Up @@ -472,6 +476,30 @@ public void usernameUnmaskedInStepArguments() {
});
}

@Issue("https://github.com/jenkinsci/credentials-plugin/pull/293")
@Test public void forRun() throws Exception {
story.then(r -> {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), new SpecialCredentials(CredentialsScope.GLOBAL, "test", null));
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("withCredentials([string(variable: 'SECRET', credentialsId: 'test')]) {echo(/got: ${SECRET.toUpperCase()}/)}", true));
r.assertLogContains("got: P#1", r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()));
});
}
private static final class SpecialCredentials extends BaseStandardCredentials implements StringCredentials {
private Run<?, ?> build;
SpecialCredentials(CredentialsScope scope, String id, String description) {
super(scope, id, description);
}
@Override public Secret getSecret() {
return Secret.fromString(build != null ? build.getExternalizableId() : "unknown");
}
@Override public Credentials forRun(Run<?, ?> context) {
SpecialCredentials clone = new SpecialCredentials(getScope(), getId(), getDescription());
clone.build = context;
return clone;
}
}

private static Set<String> grep(File dir, String text) throws IOException {
Set<String> matches = new TreeSet<>();
grep(dir, text, "", matches);
Expand Down