How to get GUID of current workspace - plasticscm

cm status gives me the changeset number of the workspace (e.g. cs:5178). Is there any way for me to retrieve the associated GUID, from the command line?

You can run the following command:
cm find changeset where changesetid=123 --format={guid} --nototal

Related

TF.exe label - Workspace mapping required when creating a label for a server item?

In my TFS release i added a script to create a label when a certain environment succeeds.
This label is apply on a given server item and for a specific Changeset.
The TF.exe command looks like this:
tf.exe label Main-Approved $/MyProject/Main /recursive /version:C124730 /comment:"Approved by Main Release" /collection:http://tfsserver:port/tfs/MyCollection
However when run from the release i get the following error message return by TF.exe:
Error: There is no working folder mapping for D:\Agent-Default_work\r144\a\by.
Running this exact command localy works fine and creates the label.
I don't understand why i would need to create a workspace and some folder mapping in order to apply a label on a Server item (using $/...) for a specific changeset?
Any help would be appreciated.
Thanks!
So i was using a Python script to run the command.
I tried changing it to a powershell script and it works.
My guess is that in python the strings were passed incorrectly someone. I feel like the workspace 'by' was in fact my command wrongly parsed by the intepreter and considered an argument in tf.exe.

How to correctly get TFS changeset number into Project Version field of SonarScanner on Jenkins?

We are running Jenkins as our build server and on-prem TFS as our source control. We are using SonarScanner for MSBuild step before the build, and one of the fields which can be populated is "project Version". The value in this field will tag the sonar analysis with the version.
I have tried the following values:
$TFS_CHANGESET
${TFS_CHANGESET}
${ENV,var="TFS_CHANGESET"}
but unfortunately I just get the literal text that is put in, not an evaluation of the environment variable.
Is there a way to get the actual environment variable evaluated and it's value used instead? The sonarqube scanner documentation does not appear to provide information on how to use environment variables, and the various posts I have read, leading to the values I have tried do not appear to work either!
Ref:
https://community.sonarsource.com/t/expand-environment-variables-in-sonarqube-scanner-for-jenkins/4711
How to correctly get TFS changeset number into Project Version field of SonarScanner on Jenkins?
If you are using the default way to download your code from Azure DevOps Server by through the usage of the Source Code Management Tab, it seems we could not configure it to download the source code by a particular changeset number.
To resolve this issue, you could use Windows batch command to get the latest source code:
%TFS% workspaces -format:brief -server:{your-tfs-team-project-collection-url}
%TFS% workspace -new Hudson-%JOB_NAME%-MASTER;{your-domain-user-name} -noprompt -server:{your-tfs-team-project-collection-url}
%TFS% workfold -map $/{tfs-path-to-your-sln} C:\Jenkins\jobs\%JOB_NAME%\workspace\ -workspace:Hudson-%JOB_NAME%-MASTER -server:{your-tfs-team-project-collection-url}
%TFS% get $/{tfs-path-to-your-sln} -force -recursive -noprompt
%TFS% history $/{tfs-path-to-your-sln} -recursive -stopafter:1 -noprompt -format:brief -server:{your-tfs-team-project-collection-url}
Please check the document Jenkins: Get Source Code By Specific TFS Changeset for some more details.
Hope this helps.

Stripping GIT_BRANCH to get the verison

I have branch with this format: release/1.0.0
When I use ${GIT_BRANCH}, I get the following: origin/release/1.0.0
I have tried using EnvInj to set a variable like this:
If I leave ${GIT_BRANCH} the way it is it works fine, but if i use ${GIT_BRANCH, fullName=false}. It is always a empty string.
I have also tried using: How to receive local Git branch name with Jenkins Git plugin?
What is correct format to get just 1.0.0.0-rc134
You can always write a small bash script to get this done.
Use a execute shell build step
echo "RELEASECANDIDATE=${GIT_BRANCH##*/}-rc${BUILD_NUMBER}" > ${WORKSPACE}/inject.txt
Use a Inject shell and in the properties file section give the file name
${WORKSPACE}/inject.txt
Finally in the update build name , use macro below variable
${RELEASECANDIDATE}
This should get you correct value as expected
Use below command at execute bash to get any part of the branch string you want. I am getting the mid part here. Keep in mind it starts counting from left and from 1.
SUBSTR=$(echo $GIT_BRANCH | cut -d'/' -f 2)
I continued the search and found a better solution for this problem at the link below. Basically rather than using $GIT_BRANCH, you can add one additional behaviour after git pull and "check out to specific local branch" and then use $GIT_LOCAL_BRANCH that will return what you expect and is compatible with all plugins (at least with FTP plugin that I used). Please see it in more details at the link below:
How to receive local Git branch name with Jenkins Git plugin?
Try to get ${GIT_LOCAL_BRANCH}. It returns only branch name.

TFS tf branch command error: no appropriate mapping exists for

I'm trying to use tf branch, but get this error:
no appropriate mapping exists for $/main_folder/folderB/folder1
below is my command:
tf branch $/main_folder/folderA/folder1/file.sql $/main_folder/folderB/folder1
Any ideas why?
The branch command copies an item or set of items, including metadata and version control history, from one location to another in the Team Foundation version control server and in the local workspace.
According to above error info, you also need to map your $/main_folder/folderB/folder1 path to your local workspace. Then try to perform the command again.
More detail tutorial about how to use this command please refer this official tutorial: Branch Command
A sample full command in cmd with using tf.exe branch command for your reference:
tf branch $/ScrumProject/TestCaseProject $/ScrumProject/Test /w:WPATRICK-W10

TFS - Getting all the change sets included in the last get

I am creating a batch build script.
I need a tfs cmd command to print all the change sets included in my get.
i failed to google it so far, appreciate any help.
I found a solution.
You can use the tf history command, you can compare the history of the local workbench vs the server.
Try this command:
tf history xxx.sln /noprompt /v:Cxx~W
Cxx: Get the changset of the time you would do the last get.
W: Specifies the version in your workspace.(Current)

Resources