Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-37778] more happy path testing
  • Loading branch information
rsandell committed Nov 4, 2016
1 parent df39786 commit 8b48858
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
Expand Up @@ -25,11 +25,14 @@

package org.jenkinsci.plugins.pipeline.modeldefinition.steps;

import com.cloudbees.hudson.plugins.folder.Folder;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import hudson.util.Secret;
import org.jenkinsci.plugins.pipeline.modeldefinition.AbstractModelDefTest;
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -58,4 +61,49 @@ public void usernamePassword() throws Exception {
.archives("combined/foo.txt", allOf(containsString(username), containsString(password)))
.archives("foo_usr.txt", username).archives("foo_psw.txt", password).go();
}

@Test
public void mixedEnv() throws Exception {
final String cred1Id = "cred1";
final String cred2Id = "cred2";

final String cred1Secret = "Some secret text for 1";
final String cred2U = "bobby";
final String cred2P = "supersecretpassword+mydogsname";

StringCredentialsImpl sc = new StringCredentialsImpl(CredentialsScope.GLOBAL, cred1Id, "test", Secret.fromString(cred1Secret));
CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), sc);
UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, cred2Id, "sample", cred2U, cred2P);
CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), c);

expect("credentials", "mixedEnv").runFromRepo(false)
.logContains("SOME_VAR is SOME VALUE",
"INBETWEEN is Something in between",
"OTHER_VAR is OTHER VALUE")
.archives("cred1.txt", cred1Secret)
.archives("cred2.txt", cred2U + ":" + cred2P).go();
}

@Test
public void mixedEnvInFolder() throws Exception {
Folder folder = j.jenkins.createProject(Folder.class, "testFolder");
final String cred1Id = "cred1";
final String cred2Id = "cred2";

final String cred1Secret = "Some secret text for 1";
final String cred2U = "bobby";
final String cred2P = "supersecretpassword+mydogsname";

StringCredentialsImpl sc = new StringCredentialsImpl(CredentialsScope.GLOBAL, cred1Id, "test", Secret.fromString(cred1Secret));
CredentialsProvider.lookupStores(folder).iterator().next().addCredentials(Domain.global(), sc);
UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, cred2Id, "sample", cred2U, cred2P);
CredentialsProvider.lookupStores(folder).iterator().next().addCredentials(Domain.global(), c);

expect("credentials", "mixedEnv").runFromRepo(false).inFolder(folder)
.logContains("SOME_VAR is SOME VALUE",
"INBETWEEN is Something in between",
"OTHER_VAR is OTHER VALUE")
.archives("cred1.txt", cred1Secret)
.archives("cred2.txt", cred2U + ":" + cred2P).go();
}
}
@@ -0,0 +1,50 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

pipeline {
environment {
SOME_VAR = "SOME VALUE"
CRED1 = credentials("cred1")
INBETWEEN = "Something in between"
CRED2 = credentials("cred2")
OTHER_VAR = "OTHER VALUE"
}

agent any

stages {
stage("foo") {
steps {
sh 'echo "SOME_VAR is $SOME_VAR"'
sh 'echo "INBETWEEN is $INBETWEEN"'
sh 'echo "OTHER_VAR is $OTHER_VAR"'

sh 'echo $CRED1 > cred1.txt'
sh 'echo $CRED2 > cred2.txt'
archive "**/*.txt"
}
}
}
}

0 comments on commit 8b48858

Please sign in to comment.