jenkinsci / azure-credentials-plugin

Jenkins Azure Credentials plugin
https://plugins.jenkins.io/azure-credentials/
MIT License
10 stars 26 forks source link

Error when I try to initialize environment variable with credentials and a Azure Credentials secret inside my Jenkins declarative pipeline #155

Closed J-Are closed 1 year ago

J-Are commented 1 year ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.263.4.2 OS: Linux - 3.10.0-1160.76.1.el7.x86_64 --- Office-365-Connector:4.14.0 ace-editor:1.1 active-directory:2.23 analysis-core:1.96 analysis-model-api:9.6.0 anchore-container-scanner:1.0.23 ansicolor:0.7.5 ant:1.11 antisamy-markup-formatter:2.1 apache-httpcomponents-client-4-api:4.5.13-1.0 artifact-manager-s3:1.12 async-http-client:1.7.24.3 authentication-tokens:1.4 aws-credentials:1.28 aws-global-configuration:1.6 aws-java-sdk:1.11.930 azure-acs:1.0.4 azure-app-service:1.0.2 azure-commons:1.0.5 azure-container-agents:1.2.0 azure-credentials:4.0.6 azure-function:0.3.3 azure-vm-agents:1.5.1 azure-vmss:0.2.4 basic-branch-build-strategies:1.3.2 blueocean:1.24.3 blueocean-autofavorite:1.2.4 blueocean-bitbucket-pipeline:1.24.3 blueocean-commons:1.24.3 blueocean-config:1.24.3 blueocean-core-js:1.24.3 blueocean-dashboard:1.24.3 blueocean-display-url:2.4.0 blueocean-events:1.24.3 blueocean-executor-info:1.24.8 blueocean-git-pipeline:1.24.3 blueocean-github-pipeline:1.24.3 blueocean-i18n:1.24.3 blueocean-jira:1.24.3 blueocean-jwt:1.24.3 blueocean-personalization:1.24.3 blueocean-pipeline-api-impl:1.24.3 blueocean-pipeline-editor:1.24.3 blueocean-pipeline-scm-api:1.24.3 blueocean-rest:1.24.3 blueocean-rest-impl:1.24.3 blueocean-web:1.24.3 bootstrap4-api:4.5.3-1 bouncycastle-api:2.18 branch-api:2.6.2 build-timeout:1.20 checks-api:1.2.0 cloud-stats:0.27 cloudbees-administrative-monitors:1.0.1 cloudbees-analytics:1.27 cloudbees-assurance:2.138.0.25 cloudbees-bitbucket-branch-source:2.9.7 cloudbees-blueocean-default-theme:0.8 cloudbees-folder:6.15 cloudbees-jenkins-advisor:3.2.3 cloudbees-license:9.51 cloudbees-support:3.26 cloudbees-uc-data-api:4.43 cmakebuilder:4.1.1 cobertura:1.17 code-coverage-api:1.3.2 command-launcher:1.5 config-file-provider:3.7.0 configuration-as-code:1.46 content-replace:1.7.0 copyartifact:1.45.3 credentials:2.3.14 credentials-binding:1.24 custom-tools-plugin:0.8 dark-theme:0.0.10 dashboard-view:2.14 data-tables-api:1.10.21-3 dependency-check-jenkins-plugin:5.1.2 dependency-track:3.1.0 devoptics:1.1973 display-url-api:2.3.4 docker-commons:1.17 docker-java-api:3.2.13-37.vf3411c9828b9 docker-plugin:1.2.9 docker-workflow:1.25 dotnet-sdk:1.1.0 dtkit-api:3.0.1 durable-task:1.35 echarts-api:4.9.0-2 email-ext:2.81 extended-choice-parameter:346.vd87693c5a_86c extended-read-permission:3.2 external-monitor-job:1.7 favorite:2.3.2 folder-properties:1.2.1 font-awesome-api:5.15.1-1 forensics-api:0.8.1 git:4.5.2 git-client:3.6.0 git-forensics:0.8.1 git-server:1.9 github:1.32.0 github-api:1.117 github-branch-source:2.9.3 gitlab-api:1.0.6 gitlab-branch-source:1.5.9 gitlab-hook:1.4.2 gitlab-logo:1.0.5 gitlab-plugin:1.5.13 google-analytics-usage-reporter:0.4 google-container-registry-auth:0.3 google-oauth-plugin:1.0.2 gravatar:2.2 greenballs:1.15.1 handlebars:1.1.1 handy-uri-templates-2-api:2.1.8-1.0 hp-application-automation-tools-plugin:7.1 htmlpublisher:1.25 hudson-wsclean-plugin:1.0.8 jackson2-api:2.12.1 javadoc:1.6 jaxb:2.3.0.1 jdk-tool:1.4 jenkins-design-language:1.24.3 jira:3.1.3 jquery:1.12.4-1 jquery-detached:1.2.1 jquery-ui:1.0.2 jquery3-api:3.5.1-2 jsch:0.1.55.2 junit:1.48 kerberos-sso:1.7 kubernetes:1.28.7 kubernetes-cd:2.3.1 kubernetes-cli:1.9.0 kubernetes-client-api:4.11.1 kubernetes-credentials:0.7.0 labelled-steps:1.0 ldap:1.26 lockable-resources:2.10 login-theme:1.1 mailer:1.32.1 mapdb-api:1.0.9.0 mask-passwords:2.13 matrix-auth:2.6.4 matrix-project:1.18 maven-plugin:3.8 mercurial:2.12 metrics:4.0.2.7 mission-control-view:0.9.16 momentjs:1.1.1 monitoring:1.91.0 msbuild:1.29 mstest:1.0.0 mstestrunner:1.3.0 nectar-license:8.29 nexus-artifact-uploader:2.13 nexus-jenkins-plugin:3.13.20211118-115856.c81882e nunit:0.27 oauth-credentials:0.4 okhttp-api:3.14.9 pam-auth:1.6 pipeline-aggregator-view:1.11 pipeline-build-step:2.13 pipeline-graph-analysis:1.10 pipeline-input-step:2.12 pipeline-milestone-step:1.3.1 pipeline-model-api:1.7.2 pipeline-model-declarative-agent:1.1.1 pipeline-model-definition:1.7.2 pipeline-model-extensions:1.7.2 pipeline-multibranch-defaults:2.1 pipeline-rest-api:2.19 pipeline-stage-step:2.5 pipeline-stage-tags-metadata:1.7.2 pipeline-stage-view:2.19 plain-credentials:1.7 plugin-util-api:1.6.1 popper-api:1.16.0-7 powershell:1.7 publish-over:0.22 publish-over-ftp:1.16 publish-over-ssh:1.22 pubsub-light:1.13 resource-disposer:0.19 ruby-runtime:0.12 scm-api:2.6.4 script-security:1.75 servicenow-cicd:2.0 shelve-project-plugin:3.2 simple-theme-plugin:103.va_161d09c38c7 skip-certificate-check:1.0 snakeyaml-api:1.27.0 soapui-pro-functional-testing:1.7 solarized-theme:0.1 sonar:2.13.1 sqlplus-script-runner:2.0.16 sse-gateway:1.24 ssh:2.6.1 ssh-credentials:1.18.1 ssh-slaves:1.31.5 ssh-steps:2.0.0 structs:1.20 support-core:2.72.1 systemloadaverage-monitor:1.2 tasks:4.53 terraform:1.0.10 test-results-analyzer:0.3.5 tfs:5.157.1 theme-manager:0.6 token-macro:2.13 tricentis-ci:1.3 trilead-api:1.0.13 update-sites-manager:2.0.0 variant:1.4 veracode-scan:22.5.17.2 violation-comments-to-gitlab:2.53 warnings:5.0.2 warnings-ng:8.6.0 windows-azure-storage:1.1.7 windows-slaves:1.7 winrm-client:1.0 workflow-aggregator:2.5 workflow-api:2.40 workflow-basic-steps:2.23 workflow-cps:2.87 workflow-cps-global-lib:2.17 workflow-durable-task-step:2.37 workflow-job:2.40 workflow-multibranch:2.22 workflow-scm-step:2.11 workflow-step-api:2.23 workflow-support:3.7 ws-cleanup:0.39 xunit:3.0.8 zap:1.1.0 ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Jenkins master host information: NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)"

Jenkins agent host information: NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)"

Reproduction steps

  1. Create a Microsoft Azure Service Principal secret in Jenkins
  2. Create a declarative Jenkins pipeline with the following code ` pipeline { agent { node { label 'your_node_label' } }

    options { ansiColor('xterm') }

    environment { ARM = credentials('my_credentials_id') }

    stages {

    stage('Terraform Init'){
      steps {
         sh """  
            echo "Test"
         """           
      }
    }

    } post { always { cleanWs() } }

} `

Expected Results

The pipeline should terminated without error when I use environment { ARM = credentials('my_credentials_id') }

Actual Results

ERROR: No suitable binding handler could be found for type com.microsoft.azure.util.AzureCredentials. Supported types are StandardUsernamePasswordCredentials,FileCredentials,DockerServerCredentials,StringCredentials,AmazonWebServicesCredentials,SSHUserPrivateKey.

Anything else?

I read the documentation https://plugins.jenkins.io/azure-credentials/#plugin-content-declarative-pipeline before doing the implementation of my Jenkins pipeline code.

timja commented 1 year ago

Support for this was added in version 216.ve0b_4a_485ffc2

You're using version 4.0.6

Also your Jenkins version looks really old and will need to be updated so you can update the plugin: 2.263.4.2

J-Are commented 1 year ago

Thank you @timja for your help. I will update it 😄