Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60392

Allow environment variables with Bitbucket Server Integration Pipeline

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When creating a pipeline build none of the options allow environment variables. The documentation I found at https://jenkins.io/doc/pipeline/steps/atlassian-bitbucket-server-integration/ states that the branch name should be able to use environment variable, however, it doesn't appear to mark it up.

       

      Hard Coded Example:

      branches: [[name: 'branchname']]

      Results:

      Produces a scan just on branch with name 'branchname'

       

      Environment Example 1:

      branches: [[name: '${ENV_VARNAME}']]

      Result:

      Produces a scan of all branches in all the repoisotry

       

      Environment Example 2:

      branches: [[name: '${env.ENV_VARNAME}']]

       Result:

      Stack Exception 

       

        Attachments

          Activity

          Hide
          mhenschke_atlassian Martin Henschke added a comment - - edited

          Hi Bruce,

          I wasn't able to reproduce this issue. I created an environment table similar to https://jenkins.io/doc/pipeline/tour/environment/ and the variable was substituted correctly. I notice in your example, you use single quotes- which when I did would attempt to scan for a branch named literally named ${ENV_VARNAME}, but with double quotes, the name was correctly substituted.

          Could you possibly provide a more complete Jenkinsfile and a snippet from the build logs, so we can investigate further?

          Show
          mhenschke_atlassian Martin Henschke added a comment - - edited Hi Bruce, I wasn't able to reproduce this issue. I created an environment table similar to https://jenkins.io/doc/pipeline/tour/environment/ and the variable was substituted correctly. I notice in your example, you use single quotes- which when I did would attempt to scan for a branch named literally named ${ENV_VARNAME}, but with double quotes, the name was correctly substituted. Could you possibly provide a more complete Jenkinsfile and a snippet from the build logs, so we can investigate further?
          Hide
          bcoveny Bruce Coveny added a comment - - edited

          Martin Henschke

          It appears using double quotes worked for the branch name but it does not appear to work for other variables like credentialsId and produces an error.  Please note values have been changed from hard-coded values for data sensitivity reasons.

          Example call:

          bbs_checkout branches: bbs_checkout branches:  [[name: "${env.BRANCH}"]],  credentialsId: "${env.CREDENTIALS_ID}",  id: 'id',  mirrorName: '',  projectName: 'project',  repositoryName: 'repo',  serverId: 'serverid'
          

          Log output: 

          [Pipeline] bbs_checkout
          using credential [proper-credential-id]
           > git.exe rev-parse --is-inside-work-tree # timeout=10
          Fetching changes from the remote Git repository
           > git.exe config remote.repo.url https://localhost:8443/scm/project/repo.git # timeout=10
          Fetching upstream changes from https://localhost:8443/scm/project/repo.git
           > git.exe --version # timeout=10
          using GIT_ASKPASS to set credentials Signon
           > git.exe fetch --tags --force --progress -- https://localhost:8443/scm/project/repo.git +refs/heads/*:refs/remotes/repo/* # timeout=10
           > git.exe rev-parse "repo/*master^{commit}" # timeout=10
           > git.exe rev-parse "develop^{commit}" # timeout=10
          [Pipeline] }
          Posting build status of FAILED to Bitbucket ServerERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
          Finished: FAILURE

          Taking out the "${env.CREDENTIALS_ID}" and changing to something like 'hardcoded-credential-id' works.

          This would work better if the payload configured in the Jenkins job could be injected as per issue JENKINS-60340 and not having to duplicate these values in the Jenkins job and in the Jenkinsfile.  We have different values for these based on different branches for access level information which is why we need to change the values around and not hard-code them in the Jenkinsfile.

          Show
          bcoveny Bruce Coveny added a comment - - edited Martin Henschke It appears using double quotes worked for the branch name but it does not appear to work for other variables like credentialsId and produces an error.  Please note values have been changed from hard-coded values for data sensitivity reasons. Example call: bbs_checkout branches: bbs_checkout branches:  [[name: "${env.BRANCH}" ]],  credentialsId: "${env.CREDENTIALS_ID}" ,  id: 'id' ,  mirrorName: '',  projectName: ' project ',  repositoryName: ' repo ',  serverId: ' serverid' Log output:  [Pipeline] bbs_checkout using credential [proper-credential-id] > git.exe rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git.exe config remote.repo.url https://localhost:8443/scm/project/repo.git # timeout=10 Fetching upstream changes from https://localhost:8443/scm/project/repo.git > git.exe --version # timeout=10 using GIT_ASKPASS to set credentials Signon > git.exe fetch --tags --force --progress -- https://localhost:8443/scm/project/repo.git +refs/heads/*:refs/remotes/repo/* # timeout=10 > git.exe rev-parse "repo/*master^{commit}" # timeout=10 > git.exe rev-parse "develop^{commit}" # timeout=10 [Pipeline] } Posting build status of FAILED to Bitbucket ServerERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job. Finished: FAILURE Taking out the "${env.CREDENTIALS_ID}" and changing to something like 'hardcoded-credential-id' works. This would work better if the payload configured in the Jenkins job could be injected as per issue  JENKINS-60340 and not having to duplicate these values in the Jenkins job and in the Jenkinsfile.  We have different values for these based on different branches for access level information which is why we need to change the values around and not hard-code them in the Jenkinsfile.

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            bcoveny Bruce Coveny
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: