Skip to content

Commit

Permalink
[FIXED JENKINS-38613] Enable specifying the credential as a parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
orrc committed Jan 11, 2018
1 parent 5dbd327 commit 8a88fbc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Expand Up @@ -40,12 +40,11 @@ public FormValidation doCheckGoogleCredentialsId(@QueryParameter String value) {
// Complain if no credentials have been set up
ListBoxModel credentials = getCredentialsListBox(GooglePlayPublisher.class);
if (credentials.isEmpty()) {
// TODO: Can we link to the credentials page from this message?
return FormValidation.error("You must add at least one Google Service Account via the Credentials page");
}

// Don't validate value if it hasn't been set
if (value == null || value.isEmpty()) {
// Don't validate value if it hasn't been set, or looks like an expression
if (value == null || value.isEmpty() || value.matches("\\$\\{[A-Za-z0-9_]+}")) {
return FormValidation.ok();
}

Expand Down
Expand Up @@ -41,9 +41,11 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul
currentListener.set(listener);
}

protected CredentialsHandler getCredentialsHandler() throws CredentialsException {
protected CredentialsHandler getCredentialsHandler() throws CredentialsException, IOException,
InterruptedException {
if (credentialsHandler == null) {
credentialsHandler = new CredentialsHandler(googleCredentialsId);
String id = expand(googleCredentialsId);
credentialsHandler = new CredentialsHandler(id);
}
return credentialsHandler;
}
Expand Down
@@ -1,8 +1,8 @@
<?jelly escape-by-default="true"?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:c="/lib/credentials">

<f:entry title="${%Google Play account}" field="googleCredentialsId">
<f:select />
<c:select expressionAllowed="true" />
</f:entry>

<f:entry title="${%APK files}" field="apkFilesPattern"
Expand Down
@@ -0,0 +1,20 @@
<div>
Specifies which credential to use in order to connect to Google Play.
<p/>
The selected credential must be a "Google Service Account from private
key" — if you have not added one already, refer to the documentation
on <a href="https://plugins.jenkins.io/google-play-android-publisher">this
plugin's page</a>.
<p/>
By choosing the "Parameter expression" option, you can also provide a
credential at build time, either from an environment variable, or from
a build parameter, e.g. the Credentials Parameter type.<br/>
But you can use any type of expression, so long as it expands to the
name of a "Google Service Account from private key" credential at
build time.
<hr/>
This field supports substituting environment variables in the form
<tt>${SOME_VARIABLE}</tt> at build time.<br/>
Note that variables in the form <tt>$SOME_VARIABLE</tt> are
<em>not</em> accepted by the Credentials Plugin.
</div>

0 comments on commit 8a88fbc

Please sign in to comment.