Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-41759] First make the function calls in environment extensible
Work in Progress
- Loading branch information
Showing
10 changed files
with
328 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...insci/plugins/pipeline/modeldefinition/environment/DeclarativeEnvironmentContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017, 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. | ||
* | ||
*/ | ||
|
||
package org.jenkinsci.plugins.pipeline.modeldefinition.environment; | ||
|
||
import org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptDescribable; | ||
import org.jenkinsci.plugins.workflow.cps.CpsScript; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Defines special functions within the environment directive. | ||
*/ | ||
public abstract class DeclarativeEnvironmentContributor<C extends WithScriptDescribable<C>> extends WithScriptDescribable<C> { | ||
|
||
public List<String> generate(CpsScript script, String key) throws Exception { | ||
return ((DeclarativeEnvironmentContributorScript)getScript(script)).generate(key); | ||
} | ||
|
||
/** | ||
* Marker interface for a generator that is not part of the standard "withEnv" flow. | ||
* But one that needs special handling. | ||
* @see com.cloudbees.plugins.credentials.CredentialsStoreAction.CredentialsWrapper | ||
*/ | ||
public interface MutedGenerator { | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ins/pipeline/modeldefinition/environment/DeclarativeEnvironmentContributorDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017, 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. | ||
* | ||
*/ | ||
|
||
package org.jenkinsci.plugins.pipeline.modeldefinition.environment; | ||
|
||
import org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptDescriptor; | ||
|
||
/** | ||
* Created by rsandell on 2017-02-06. | ||
*/ | ||
public class DeclarativeEnvironmentContributorDescriptor<C extends DeclarativeEnvironmentContributor<C>> extends WithScriptDescriptor<C> { | ||
|
||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...plugins/pipeline/modeldefinition/environment/DeclarativeEnvironmentContributorScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017, 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. | ||
* | ||
*/ | ||
|
||
package org.jenkinsci.plugins.pipeline.modeldefinition.environment; | ||
|
||
import org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptScript; | ||
import org.jenkinsci.plugins.workflow.cps.CpsScript; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Script base for {@link DeclarativeEnvironmentContributor}s. | ||
*/ | ||
public abstract class DeclarativeEnvironmentContributorScript<C extends DeclarativeEnvironmentContributor<C>> extends WithScriptScript<C> { | ||
|
||
|
||
public DeclarativeEnvironmentContributorScript(CpsScript s, C d) { | ||
super(s, d); | ||
} | ||
|
||
public abstract List<String> generate(String key); | ||
} |
87 changes: 87 additions & 0 deletions
87
...ain/java/org/jenkinsci/plugins/pipeline/modeldefinition/environment/impl/Credentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017, 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. | ||
* | ||
*/ | ||
|
||
package org.jenkinsci.plugins.pipeline.modeldefinition.environment.impl; | ||
|
||
import hudson.Extension; | ||
import org.jenkinsci.Symbol; | ||
import org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException; | ||
import org.jenkinsci.plugins.pipeline.modeldefinition.environment.DeclarativeEnvironmentContributor; | ||
import org.jenkinsci.plugins.pipeline.modeldefinition.environment.DeclarativeEnvironmentContributorDescriptor; | ||
import org.jenkinsci.plugins.pipeline.modeldefinition.model.CredentialsBindingHandler; | ||
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted; | ||
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Provides credentials function. | ||
*/ | ||
public class Credentials extends DeclarativeEnvironmentContributor<Credentials> implements DeclarativeEnvironmentContributor.MutedGenerator { | ||
|
||
private final String credentialsId; | ||
private List<Map<String, Object>> withCredentialsParameters; | ||
|
||
@DataBoundConstructor | ||
public Credentials(String credentialsId) { | ||
this.credentialsId = credentialsId; | ||
} | ||
|
||
public String getCredentialsId() { | ||
return credentialsId; | ||
} | ||
|
||
public void prepare(RunWrapper currentBuild) throws CredentialNotFoundException { | ||
CredentialsBindingHandler handler = CredentialsBindingHandler.forId(credentialsId, currentBuild.getRawBuild()); | ||
withCredentialsParameters = handler.getWithCredentialsParameters(credentialsId); | ||
} | ||
|
||
@Whitelisted | ||
public List<Map<String, Object>> resolveParameters(String envVarName) { | ||
List<Map<String, Object>> newList = new ArrayList<>(withCredentialsParameters.size()); | ||
for (Map<String, Object> params : withCredentialsParameters) { | ||
Map<String, Object> newP = new HashMap<>(); | ||
for (Map.Entry<String, Object> p : params.entrySet()) { | ||
Object value = p.getValue(); | ||
if (value instanceof CredentialsBindingHandler.EnvVarResolver) { | ||
newP.put(p.getKey(), ((CredentialsBindingHandler.EnvVarResolver)value).resolve(envVarName)); | ||
} else { | ||
newP.put(p.getKey(), p.getValue()); | ||
} | ||
} | ||
newList.add(newP); | ||
} | ||
return newList; | ||
} | ||
|
||
@Extension @Symbol("credentials") | ||
public static class DescriptorImpl extends DeclarativeEnvironmentContributorDescriptor<Credentials> { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.