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

While setting workspace name in Pipeline project for TFS unable to use Environment variable like BUILD_ID

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Critical
    • Resolution: Unresolved
    • Component/s: tfs-plugin
    • Labels:
      None
    • Environment:
      Jenkins - 2.176
    • Similar Issues:

      Description

      Hi,

      We are setting up a Pipeline project to use Jenkinsfile, we have our repository in Azure DevOps and while specifying the name space we would like to give it like 'BUILD_ID-JOB_NAME'. Since we want to use single pipeline to build multiple projects so we want to have unique workspace name. But the above mentioned format is not working, it's unable to resolve the BUILD_ID in workspace name.

      Can someone please help to resolve this issue.

        Attachments

          Activity

          Hide
          monish_ratanji Monish Ratanji added a comment -

          Hello! Would it be possible to switch to using a scripted or declarative pipeline? You should be able to invoke the Groovy string interpolation that way.

          Here's an example of what my company is doing:

          script {
          	def tfsCheckout = [$class: 'TeamFoundationServerScm', credentialsConfigurer: [$class: 'AutomaticCredentialsConfigurer'], projectPath: '$/some/path', serverUrl: "${env.TFS_SERVER_URL}, workspaceName: "${env.JOB_NAME}-${env.BUILD_NUMBER}"]
          	def tf_data = checkout tfsCheckout
          	env.TFS_CHANGESET = tf_data.TFS_CHANGESET
          	env.TFS_PROJECTPATH = tf_data.TFS_PROJECTPATH
          	env.TFS_SERVERURL = tf_data.TFS_SERVERURL
          	env.TFS_WORKFOLDER = tf_data.TFS_WORKFOLDER
          	env.TFS_WORKSPACE = tf_data.TFS_WORKSPACE
          }

          By using the string interpolation we can leave the variable expansion to Jenkins itself rather than the TFS plugin.

          If you want to continue using Freestyle jobs, I'm afraid I don't have much of a solution. The TFS plugin only expands a few specific variables for the Workspace name (JOB_NAME, USER_NAME, NODE_NAME). You can find the source code here:
          https://github.com/jenkinsci/tfs-plugin/blob/aea4ce0f1fd82668b1ead7e2aade2ffe36a32a10/tfs/src/main/java/hudson/plugins/tfs/util/BuildVariableResolver.java#L32

          I could be completely wrong here though, so someone please correct me if I am wrong

          Show
          monish_ratanji Monish Ratanji added a comment - Hello! Would it be possible to switch to using a scripted or declarative pipeline? You should be able to invoke the Groovy string interpolation that way. Here's an example of what my company is doing: script { def tfsCheckout = [$class: 'TeamFoundationServerScm', credentialsConfigurer: [$class: 'AutomaticCredentialsConfigurer'], projectPath: '$/some/path', serverUrl: "${env.TFS_SERVER_URL}, workspaceName: "${env.JOB_NAME}-${env.BUILD_NUMBER}"] def tf_data = checkout tfsCheckout env.TFS_CHANGESET = tf_data.TFS_CHANGESET env.TFS_PROJECTPATH = tf_data.TFS_PROJECTPATH env.TFS_SERVERURL = tf_data.TFS_SERVERURL env.TFS_WORKFOLDER = tf_data.TFS_WORKFOLDER env.TFS_WORKSPACE = tf_data.TFS_WORKSPACE } By using the string interpolation we can leave the variable expansion to Jenkins itself rather than the TFS plugin. If you want to continue using Freestyle jobs, I'm afraid I don't have much of a solution. The TFS plugin only expands a few specific variables for the Workspace name (JOB_NAME, USER_NAME, NODE_NAME). You can find the source code here: https://github.com/jenkinsci/tfs-plugin/blob/aea4ce0f1fd82668b1ead7e2aade2ffe36a32a10/tfs/src/main/java/hudson/plugins/tfs/util/BuildVariableResolver.java#L32 I could be completely wrong here though, so someone please correct me if I am wrong

            People

            • Assignee:
              redsolo redsolo
              Reporter:
              pradheeps Pradheep S
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: