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

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • tfs-plugin
    • None
    • Jenkins - 2.176

      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.

          [JENKINS-63238] While setting workspace name in Pipeline project for TFS unable to use Environment variable like BUILD_ID

          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

          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

          Ian Williams added a comment -

          redsolo is no longer maintaining plugin; unassigned issues

          Ian Williams added a comment - redsolo is no longer maintaining plugin; unassigned issues

            Unassigned Unassigned
            pradheeps Pradheep S
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: