本文整理汇总了Java中org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl类的典型用法代码示例。如果您正苦于以下问题:Java StringCredentialsImpl类的具体用法?Java StringCredentialsImpl怎么用?Java StringCredentialsImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringCredentialsImpl类属于org.jenkinsci.plugins.plaincredentials.impl包,在下文中一共展示了StringCredentialsImpl类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: newTokenCredentials
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
/**
* Helper method to update a credential stored within the Jenkins Credential Store. This creates a new credential
* to replace tokenCredentials.
*
* @param tokenCredentials The current, existing credential to update.
* @param token New token value for credential
* @return New Credentials constructed from tokenCredentials
*/
StringCredentials newTokenCredentials(final StringCredentials tokenCredentials, final String token) {
// retrieved a new token, now to update the existing credential in `tokenCredentials`
JSONObject json;
try {
json = JSONObject.fromObject(tokenCredentials.getSecret().getPlainText());
} catch (JSONException jse) {
json = new JSONObject();
}
json.put("jenkins_token", token);
return new StringCredentialsImpl(
tokenCredentials.getScope(),
tokenCredentials.getId(),
tokenCredentials.getDescription(),
Secret.fromString(json.toString()));
}
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:25,代码来源:TokenAuthProvider.java
示例2: testRecorderInvalidToken
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
/**
* Test that a JSON credential without a "jenkins_token" field and without a proper DC/OS service account value
* results in a 401 and only 1 web request.
*
* @throws Exception
*/
@Test
public void testRecorderInvalidToken() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject();
final SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
final CredentialsStore systemStore = system.getStore(j.getInstance());
final String credentialValue = "{\"field1\":\"some value\"}";
final Secret secret = Secret.fromString(credentialValue);
final StringCredentials credential = new StringCredentialsImpl(CredentialsScope.GLOBAL, "invalidtoken", "a token for JSON token test", secret);
TestUtils.enqueueFailureResponse(httpServer, 401);
systemStore.addCredentials(Domain.global(), credential);
addBuilders(TestUtils.loadFixture("idonly.json"), project);
// add post-builder
addPostBuilders(project, "invalidtoken");
final FreeStyleBuild build = j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get());
j.assertLogContains("[Marathon] Authentication to Marathon instance failed:", build);
j.assertLogContains("[Marathon] Invalid DC/OS service account JSON", build);
assertEquals("Only 1 request should have been made.", 1, httpServer.getRequestCount());
}
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:29,代码来源:MarathonRecorderTest.java
示例3: prepareGitHubPlugin
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
/**
* Prepare global GitHub plugin configuration.
* Nothing specific to job.
*/
public static GitHubServerConfig prepareGitHubPlugin() {
// prepare global jRule settings
final StringCredentialsImpl cred = new StringCredentialsImpl(
CredentialsScope.GLOBAL,
null,
"description",
Secret.fromString(GH_TOKEN)
);
SystemCredentialsProvider.getInstance().getCredentials().add(cred);
final GitHubPluginConfig gitHubPluginConfig = GitHubPlugin.configuration();
final List<GitHubServerConfig> gitHubServerConfigs = new ArrayList<>();
final GitHubServerConfig gitHubServerConfig = new GitHubServerConfig(cred.getId());
gitHubServerConfig.setManageHooks(false);
gitHubServerConfig.setClientCacheSize(0);
gitHubServerConfigs.add(gitHubServerConfig);
gitHubPluginConfig.setConfigs(gitHubServerConfigs);
return gitHubServerConfig;
}
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:28,代码来源:GHRule.java
示例4: addAliases
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void addAliases() {
Jenkins.XSTREAM2.addCompatibilityAlias(
"org.csanchez.jenkins.plugins.kubernetes.OpenShiftBearerTokenCredentialImpl",
org.jenkinsci.plugins.kubernetes.credentials.OpenShiftBearerTokenCredentialImpl.class);
Jenkins.XSTREAM2.addCompatibilityAlias(
"org.csanchez.jenkins.plugins.kubernetes.OpenShiftTokenCredentialImpl",
StringCredentialsImpl.class);
Jenkins.XSTREAM2.addCompatibilityAlias("org.csanchez.jenkins.plugins.kubernetes.ServiceAccountCredential",
org.jenkinsci.plugins.kubernetes.credentials.FileSystemServiceAccountCredential.class);
}
开发者ID:carlossg,项目名称:jenkins-kubernetes-plugin,代码行数:12,代码来源:KubernetesCloud.java
示例5: incorrectType
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Test public void incorrectType() throws Exception {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
StringCredentialsImpl c = new StringCredentialsImpl(CredentialsScope.GLOBAL, "creds", "sample", Secret.fromString("s3cr3t"));
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), c);
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " withCredentials([usernamePassword(usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD', credentialsId: 'creds')]) {\n"
+ " }\n"
+ "}", true));
WorkflowRun r = story.j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
// make sure error message contains information about the actual type and the expected type
story.j.assertLogNotContains("s3cr3t", r);
story.j.assertLogContains(CredentialNotFoundException.class.getName(), r);
story.j.assertLogContains(StandardUsernamePasswordCredentials.class.getName(), r);
story.j.assertLogContains(stringCredentialsDescriptor.getDisplayName(), r);
}
});
}
开发者ID:jenkinsci,项目名称:credentials-binding-plugin,代码行数:22,代码来源:BindingStepTest.java
示例6: grabEnv
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Issue("JENKINS-27389")
@Test public void grabEnv() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
String credentialsId = "creds";
String secret = "s3cr3t";
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample", Secret.fromString(secret)));
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(""
+ "def extract(id) {\n"
+ " def v\n"
+ " withCredentials([string(credentialsId: id, variable: 'temp')]) {\n"
+ " v = env.temp\n"
+ " }\n"
+ " v\n"
+ "}\n"
+ "node {\n"
+ " echo \"got: ${extract('" + credentialsId + "')}\"\n"
+ "}", true));
story.j.assertLogContains("got: " + secret, story.j.assertBuildStatusSuccess(p.scheduleBuild2(0).get()));
}
});
}
开发者ID:jenkinsci,项目名称:credentials-binding-plugin,代码行数:24,代码来源:BindingStepTest.java
示例7: masking
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Issue("JENKINS-27486")
@Test public void masking() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
String credentialsId = "creds";
String secret = "s3cr3t";
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample", Secret.fromString(secret)));
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " withCredentials([string(credentialsId: '" + credentialsId + "', variable: 'SECRET')]) {\n"
// forgot set +x, ran /usr/bin/env, etc.
+ " if (isUnix()) {sh 'echo $SECRET > oops'} else {bat 'echo %SECRET% > oops'}\n"
+ " }\n"
+ "}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0).get());
story.j.assertLogNotContains(secret, b);
story.j.assertLogContains("echo ****", b);
}
});
}
开发者ID:jenkinsci,项目名称:credentials-binding-plugin,代码行数:22,代码来源:BindingStepTest.java
示例8: secretBuildWrapperRunsBeforeNormalWrapper
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Issue("JENKINS-37871")
@Test public void secretBuildWrapperRunsBeforeNormalWrapper() throws Exception {
StringCredentialsImpl firstCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample1", Secret.fromString(password));
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), firstCreds);
SecretBuildWrapper wrapper = new SecretBuildWrapper(Arrays.asList(new StringBinding(bindingKey, credentialsId)));
FreeStyleProject f = r.createFreeStyleProject("buildWrapperOrder");
f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_1%") : new Shell("echo $PASS_1"));
f.getBuildWrappersList().add(new BuildWrapperOrder());
f.getBuildWrappersList().add(wrapper);
// configRoundtrip makes sure the ordinal of SecretBuildWrapper extension is applied correctly.
r.configRoundtrip(f);
FreeStyleBuild b = r.buildAndAssertSuccess(f);
r.assertLogContains("Secret found!", b);
}
开发者ID:jenkinsci,项目名称:credentials-binding-plugin,代码行数:21,代码来源:BuildWrapperOrderCredentialsBindingTest.java
示例9: testRecorderBasicToken
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
/**
* Test a basic API token using StringCredentials.
*
* @throws Exception
*/
@Test
public void testRecorderBasicToken() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject();
final String responseStr = "{\"version\": \"one\", \"deploymentId\": \"someid-here\"}";
final SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
final CredentialsStore systemStore = system.getStore(j.getInstance());
final String tokenValue = "my secret token";
final Secret secret = Secret.fromString(tokenValue);
final StringCredentials credential = new StringCredentialsImpl(CredentialsScope.GLOBAL, "basictoken", "a token for basic token test", secret);
TestUtils.enqueueJsonResponse(httpServer, responseStr);
systemStore.addCredentials(Domain.global(), credential);
// add builders
addBuilders(TestUtils.loadFixture("idonly.json"), project);
// add post-builder
addPostBuilders(project, "basictoken");
final FreeStyleBuild build = j.assertBuildStatusSuccess(project.scheduleBuild2(0).get());
j.assertLogContains("[Marathon]", build);
// handler assertions
assertEquals("Only 1 request should be made", 1, httpServer.getRequestCount());
RecordedRequest request = httpServer.takeRequest();
final String authorizationText = request.getHeader("Authorization");
assertEquals("Token does not match", "token=" + tokenValue, authorizationText);
}
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:33,代码来源:MarathonRecorderTest.java
示例10: testRecorderJSONToken
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
/**
* Test that a JSON credential with "jenkins_token" uses the token value as the authentication token.
*
* @throws Exception
*/
@Test
public void testRecorderJSONToken() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject();
final String responseStr = "{\"version\": \"one\", \"deploymentId\": \"someid-here\"}";
final SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
final CredentialsStore systemStore = system.getStore(j.getInstance());
final String tokenValue = "my secret token";
final String credentialValue = "{\"field1\":\"some value\", \"jenkins_token\":\"" + tokenValue + "\"}";
final Secret secret = Secret.fromString(credentialValue);
final StringCredentials credential = new StringCredentialsImpl(CredentialsScope.GLOBAL, "jsontoken", "a token for JSON token test", secret);
TestUtils.enqueueJsonResponse(httpServer, responseStr);
systemStore.addCredentials(Domain.global(), credential);
// add builders
addBuilders(TestUtils.loadFixture("idonly.json"), project);
// add post-builder
addPostBuilders(project, "jsontoken");
final FreeStyleBuild build = j.assertBuildStatusSuccess(project.scheduleBuild2(0).get());
j.assertLogContains("[Marathon]", build);
// handler assertions
assertEquals("Only 1 request should be made", 1, httpServer.getRequestCount());
RecordedRequest request = httpServer.takeRequest();
final String authorizationText = request.getHeader("Authorization");
assertEquals("Token does not match", "token=" + tokenValue, authorizationText);
}
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:34,代码来源:MarathonRecorderTest.java
示例11: createCredentials
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
public static String createCredentials(String serverAPIUrl, String token) throws Exception {
String description = serverAPIUrl + " GitHub auto generated token credentials";
StringCredentialsImpl credentials = new StringCredentialsImpl(
CredentialsScope.GLOBAL,
UUID.randomUUID().toString(),
description,
Secret.fromString(token));
return createCredentials(serverAPIUrl, credentials);
}
开发者ID:bratchenko,项目名称:jenkins-github-pull-request-comments,代码行数:10,代码来源:Ghprc.java
示例12: upgradeFrom_1_1
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Test
@LocalData()
public void upgradeFrom_1_1() throws Exception {
List<Credentials> credentials = SystemCredentialsProvider.getInstance().getCredentials();
assertEquals(3, credentials.size());
UsernamePasswordCredentialsImpl cred0 = (UsernamePasswordCredentialsImpl) credentials.get(0);
assertEquals("token", cred0.getId());
assertEquals("myusername", cred0.getUsername());
FileSystemServiceAccountCredential cred1 = (FileSystemServiceAccountCredential) credentials.get(1);
StringCredentialsImpl cred2 = (StringCredentialsImpl) credentials.get(2);
assertEquals("mytoken", Secret.toString(cred2.getSecret()));
}
开发者ID:carlossg,项目名称:jenkins-kubernetes-plugin,代码行数:13,代码来源:KubernetesTest.java
示例13: addGitLabApiToken
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
static void addGitLabApiToken() throws IOException {
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
List<Domain> domains = credentialsStore.getDomains();
credentialsStore.addCredentials(domains.get(0),
new StringCredentialsImpl(CredentialsScope.SYSTEM, API_TOKEN_ID, "GitLab API Token", Secret.fromString(API_TOKEN)));
}
}
}
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:10,代码来源:TestUtility.java
示例14: setupGitLabConnections
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
static void setupGitLabConnections(JenkinsRule jenkins, MockServerRule mockServer) throws IOException {
GitLabConnectionConfig connectionConfig = jenkins.get(GitLabConnectionConfig.class);
String apiTokenId = "apiTokenId";
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
List<Domain> domains = credentialsStore.getDomains();
credentialsStore.addCredentials(domains.get(0),
new StringCredentialsImpl(CredentialsScope.SYSTEM, apiTokenId, "GitLab API Token", Secret.fromString(TestUtility.API_TOKEN)));
}
}
connectionConfig.addConnection(new GitLabConnection(TestUtility.GITLAB_CONNECTION_V3, "http://localhost:" + mockServer.getPort() + "/gitlab", apiTokenId, new V3GitLabClientBuilder(), false, 10, 10));
connectionConfig.addConnection(new GitLabConnection(TestUtility.GITLAB_CONNECTION_V4, "http://localhost:" + mockServer.getPort() + "/gitlab", apiTokenId, new V4GitLabClientBuilder(), false, 10, 10));
}
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:15,代码来源:TestUtility.java
示例15: setup
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Before
public void setup() throws IOException {
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
List<Domain> domains = credentialsStore.getDomains();
credentialsStore.addCredentials(domains.get(0),
new StringCredentialsImpl(CredentialsScope.SYSTEM, API_TOKEN_ID, "GitLab API Token", Secret.fromString(API_TOKEN_ID)));
}
}
}
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:11,代码来源:GitLabConnectionConfigSSLTest.java
示例16: setup
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Before
public void setup() throws IOException {
gitLabUrl = "http://localhost:" + mockServer.getPort() + "/gitlab";
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
List<Domain> domains = credentialsStore.getDomains();
credentialsStore.addCredentials(domains.get(0),
new StringCredentialsImpl(CredentialsScope.SYSTEM, API_TOKEN_ID, "GitLab API Token", Secret.fromString(API_TOKEN)));
}
}
}
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:12,代码来源:GitLabConnectionConfigTest.java
示例17: createGitLabConnectionProperty
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
public GitLabConnectionProperty createGitLabConnectionProperty() throws IOException {
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
List<Domain> domains = credentialsStore.getDomains();
credentialsStore.addCredentials(domains.get(0),
new StringCredentialsImpl(CredentialsScope.SYSTEM, API_TOKEN_ID, "GitLab API Token", Secret.fromString(getApiToken())));
}
}
GitLabConnectionConfig config = Jenkins.getInstance().getDescriptorByType(GitLabConnectionConfig.class);
GitLabConnection connection = new GitLabConnection("test", url, API_TOKEN_ID, new V3GitLabClientBuilder(), true,10, 10);
config.addConnection(connection);
config.save();
return new GitLabConnectionProperty(connection.getName());
}
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:16,代码来源:GitLabRule.java
示例18: maskingFreeStyleSecrets
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Issue("JENKINS-24805")
@Test public void maskingFreeStyleSecrets() throws Exception {
String firstCredentialsId = "creds_1";
String firstPassword = "p4$$";
StringCredentialsImpl firstCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, firstCredentialsId, "sample1", Secret.fromString(firstPassword));
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), firstCreds);
String secondCredentialsId = "creds_2";
String secondPassword = "p4$$" + "someMoreStuff";
StringCredentialsImpl secondCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, secondCredentialsId, "sample2", Secret.fromString(secondPassword));
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), secondCreds);
SecretBuildWrapper wrapper = new SecretBuildWrapper(Arrays.asList(new StringBinding("PASS_1", firstCredentialsId),
new StringBinding("PASS_2", secondCredentialsId)));
FreeStyleProject f = r.createFreeStyleProject();
f.setConcurrentBuild(true);
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);
FreeStyleBuild b = r.buildAndAssertSuccess(f);
r.assertLogNotContains(firstPassword, b);
r.assertLogNotContains(secondPassword, b);
r.assertLogContains("****", b);
}
开发者ID:jenkinsci,项目名称:credentials-binding-plugin,代码行数:32,代码来源:SecretBuildWrapperTest.java
示例19: emptySecret
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Issue("JENKINS-41760")
@Test public void emptySecret() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), new StringCredentialsImpl(CredentialsScope.GLOBAL, "creds", null, Secret.fromString("")));
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.singletonList(new StringBinding("SECRET", "creds"))));
p.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo PASSES") : new Shell("echo PASSES"));
r.assertLogContains("PASSES", r.buildAndAssertSuccess(p));
}
开发者ID:jenkinsci,项目名称:credentials-binding-plugin,代码行数:9,代码来源:SecretBuildWrapperTest.java
示例20: testTrackingOfCredential
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; //导入依赖的package包/类
@Issue("JENKINS-38831")
@Test
public void testTrackingOfCredential() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
String credentialsId = "creds";
String secret = "s3cr3t";
StringCredentialsImpl credentials = new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample", Secret.fromString(secret));
Fingerprint fingerprint = CredentialsProvider.getFingerprintOf(credentials);
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), credentials);
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(""
+ "def extract(id) {\n"
+ " def v\n"
+ " withCredentials([[$class: 'StringBinding', credentialsId: id, variable: 'temp']]) {\n"
+ " v = env.temp\n"
+ " }\n"
+ " v\n"
+ "}\n"
+ "node {\n"
+ " echo \"got: ${extract('" + credentialsId + "')}\"\n"
+ "}", true));
assertThat("No fingerprint created until first use", fingerprint, nullValue());
story.j.assertLogContains("got: " + secret, story.j.assertBuildStatusSuccess(p.scheduleBuild2(0).get()));
fingerprint = CredentialsProvider.getFingerprintOf(credentials);
assertThat(fingerprint, notNullValue());
assertThat(fingerprint.getJobs(), hasItem(is(p.getFullName())));
}
});
}
开发者ID:jenkinsci,项目名称:credentials-binding-plugin,代码行数:36,代码来源:BindingStepTest.java
注:本文中的org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论