diff --git a/pom.xml b/pom.xml index 48492b66..6ddec9fb 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 1.28 -SNAPSHOT - 2.249.1 + 2.319.1 8 @@ -54,8 +54,8 @@ io.jenkins.tools.bom - bom-2.249.x - 984.vb5eaac999a7e + bom-2.319.x + 1210.vcd41f6657f03 import pom @@ -65,6 +65,7 @@ org.jenkins-ci.plugins credentials + 1087.v16065d268466 org.jenkins-ci.plugins diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java index 9c6bad1e..450a9533 100644 --- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java @@ -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; @@ -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; @@ -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; @@ -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 grep(File dir, String text) throws IOException { Set matches = new TreeSet<>(); grep(dir, text, "", matches);