Class AzureCredentialsBinding

java.lang.Object
hudson.model.AbstractDescribableImpl<org.jenkinsci.plugins.credentialsbinding.MultiBinding<C>>
org.jenkinsci.plugins.credentialsbinding.MultiBinding<AzureCredentials>
com.microsoft.azure.util.AzureCredentialsBinding
All Implemented Interfaces:
ExtensionPoint, Describable<org.jenkinsci.plugins.credentialsbinding.MultiBinding<AzureCredentials>>

public class AzureCredentialsBinding extends org.jenkinsci.plugins.credentialsbinding.MultiBinding<AzureCredentials>
Custom binding for AzureCredentials to support reading Azure service principal in both freestyle and pipeline using Credentials Binding plugin. There're two ways to construct this binding:
  1. With defaults, which will read specified service principal into four predefined environment variables: AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID. Sample pipeline code:
    
         withCredentials([azureServicePrincipal('credentials_id')]) {
             sh 'az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID'
         }
     
  2. With custom name, where you can control the names of the variables. Sample pipeline code:
    
         withCredentials([azureServicePrincipal(credentialsId: 'credentials_id',
                                                subscriptionIdVariable: 'SUBS_ID',
                                                clientIdVariable: 'CLIENT_ID',
                                                clientSecretVariable: 'CLIENT_SECRET',
                                                tenantIdVariable: 'TENANT_ID')]) {
             sh 'az login --service-principal -u $CLIENT_ID -p $CLIENT_SECRET -t $TENANT_ID'
         }
     
  • Field Details

  • Constructor Details

    • AzureCredentialsBinding

      @DataBoundConstructor public AzureCredentialsBinding(String credentialsId)
  • Method Details

    • setSubscriptionIdVariable

      @DataBoundSetter public void setSubscriptionIdVariable(String subscriptionIdVariable)
    • setClientIdVariable

      @DataBoundSetter public void setClientIdVariable(String clientIdVariable)
    • setClientSecretVariable

      @DataBoundSetter public void setClientSecretVariable(String clientSecretVariable)
    • setTenantIdVariable

      @DataBoundSetter public void setTenantIdVariable(String tenantIdVariable)
    • getSubscriptionIdVariable

      public String getSubscriptionIdVariable()
    • getClientIdVariable

      public String getClientIdVariable()
    • getClientSecretVariable

      public String getClientSecretVariable()
    • getTenantIdVariable

      public String getTenantIdVariable()
    • type

      protected Class<AzureCredentials> type()
      Specified by:
      type in class org.jenkinsci.plugins.credentialsbinding.MultiBinding<AzureCredentials>
    • bind

      public org.jenkinsci.plugins.credentialsbinding.MultiBinding.MultiEnvironment bind(@NonNull Run<?,?> build, FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException
      Specified by:
      bind in class org.jenkinsci.plugins.credentialsbinding.MultiBinding<AzureCredentials>
      Throws:
      IOException
      InterruptedException
    • variables

      public Set<String> variables(Run<?,?> build)
      Overrides:
      variables in class org.jenkinsci.plugins.credentialsbinding.MultiBinding<AzureCredentials>