TFS and Microsoft Dynamics 365: Solution Name and Version to corresponding variable in VSTS - dynamics-crm

Lets say i have a solution named "Dynamics_1_2_3_4.zip".I want the Name, the versions (1,2,3,4) to store in different corresponding variable in VSTS. How do I achieve this?
SolutionName = Dynamics
SolutionVersionMajor = 1
SolutionVersionMinor = 2
SolutionVersionBuild = 3
SolutionVersionRevision 4
My goal is to increment the value on one of the Solution Version. Thanks

As I already answered on GitHub.
You can add a PowerShell step with something like this in it:
"MySolution_1_2_3_4.zip" -match "^(?<name>\w+?)_(?<major>\d+)_(?<minor>\d+)_(?<build>\d+)_(?<revision>\d+).zip$"
Write-Host "##vso[task.setvariable variable=SolutionName;]$($matches['name'])"
Write-Host "##vso[task.setvariable variable=SolutionVersionMajor;]$($matches['major'])"
Write-Host "##vso[task.setvariable variable=SolutionVersionMinor;]$($matches['minor'])"
Write-Host "##vso[task.setvariable variable=SolutionVersionBuild;]$($matches['build'])"
Write-Host "##vso[task.setvariable variable=SolutionVersionRevision;]$($matches['revision'])"
After the step VSTS will have the variables available like $(SolutionVersionBuild)

Refer to these steps below:
Add PowerShell task (Type: Inline Script; Arguments: -p [The folder path of file, such as $(Build.SourcesDirectory)];
Scripts:
param(
[string]$p
)
Write-Host $p
$files=Get-ChildItem -Path "$p\Dynamics*.zip"
$name=$files[0].name.Split('\')[-1]
Write-Host $name
# scripts as Michael said
Note: $(Build.SourcesDirectory) is the local path on the agent where your source code files are downloaded. For example: c:\agent_work\1\s

Related

Powershell commands for Process Template Editor and DevOps similar to PowerTools and TFS

I was able to run the following commands in Powershell with PowerTools and TFS. What are the equivalent Powershell commands for Process Template Editor and DevOps please? Or is there any other way of doing this in Powershell with DevOps Server 2020?
add-pssnapin Microsoft.TeamFoundation.PowerShell
Get-TfsServer -name $tfsServer | out-null
# Retrieve the TFS item properties
$x = Get-TfsItemProperty -Item $itemFilePath
# Does the item exist in TFS
if ($x.IsInWorkspace -ne $null)
# Is the item checked out?
if ($x.LockOwner -ne $null)
# Is the item checked out to someone else?
if ($x.LockOwner -ne $myUser)
# Add the item to TFS
Add-TfsPendingChange -Add -Item $itemFilePath | out-null
# File exists and is not checked out, Check it out
Add-TfsPendingChange -Edit -Item $itemFilePath | out-null
# Check in the file
$x = New-TfsChangeset -Item $itemFilePath -Comment $itemComment

How to get current Build definition name using PowerShell in TFS

We are using TFSdeployer to trigger Build deployment to deploy build.
But stuck with how to get Build definition of the current Build for which we trying and could not succeed.
How to get current Build definition name using below PowerShell script instead of hardcode.
Scenario: If i trigger from Test1 BuildQuality then first code should be working . If i trigger from Test2 BuildQuality then second code should be working. (If-Else code is working perfectly)
Tried using $TFSDeployerBuildDetail.DefinitionName
$Build.Name
But that seems to be not working, Any help is appreciated.
$BuildDefinitionName = "Test1"
$PackagePath = "C:\extra\Package_Files"
$DestPath1 ="C:\extra\Test1"
$DestPath2 ="C:\extra\Test2"
$logFile ="C:\extra\logs"
$utilPath = "C:\util\"
if ($BuildDefinitionName -eq "Test1")
{
Write-Host "Testing 1st Copy"
Add-Content -Path $logFile "Copying to Test1"
& $utilPath\robocopy $PackagePath $DestPath1 /s >> $logFile
}
elseif($BuildDefinitionName -eq "Test2")
{
Write-Host "Testing 2nd Copy"
Add-Content -Path $logFile "Copying to Test2"
& $utilPath\robocopy $PackagePath $DestPath2 /s >> $logFile
}
Use the provided environment variable:
$env:BUILD_DEFINITIONNAME
https://learn.microsoft.com/en-us/vsts/build-release/actions/scripts/powershell
Since you indicated you're using XAML build, the environment variable would be $env:TF_BUILD_BUILDDEFINITIONNAME.
The other answer is correct for the newer, web-based build system.

Can I add a custom step to a nuget install

I'm investigating ways to allow many website projects to pull from the same collection of CSS/JS/HTML and have that collection be updated once and then delivered to all the projects that use it.
At the moment, I'm exploring using a NuGet package (my company uses TFS and VS so it seems the logical package manager) to deliver the styles, and using the content folder to deliver the files directly into the project. However, each project is going to need those files in different locations in order to work properly.
Is there a way to add a custom script to a post-install/update of a NuGet package for each project?
For those of you in the future:
In your package: tools/install.ps1
param($installPath, $toolsPath, $package, $project)
$projectFullName = $project.FullName
$debugString = "install.ps1 executing for " + $projectFullName
Write-Host $debugString
$fileInfo = new-object -typename System.IO.FileInfo -ArgumentList $projectFullName
$projectDirectory = $fileInfo.DirectoryName
$customInstallFile = $projectDirectory + "\" + $package.Id + ".ps1"
Write-Host "looking for" $customInstallFile
if(Test-Path $customInstallFile){
Write-Host "found it"
& $customInstallFile
} else {
Write-Host "not found"
}
Write-Host "Installation Complete"
And in your project's root folder: [packageId].ps1
Write-Host "Hello world!"

Is there a way to modify TeamCity system properties in a shell script?

I'm trying to figure out how to modify some custom system properties that I've defined in the build configurations parameters.
For example, if I have a system property named system.TestProperty with value 0 and I want to modify it's value from shell, I've tryed using ##teamcity[setParameter name='system.TestProperty' value='1'] as explained here but the next time I get it's value, it gives me 0 again.
The script i'm using to test:
Write-Host "-------------"
$testProperty = "%system.TestProperty%"
Write-Host "system.TestProperty: $testProperty"
Write-Host "##teamcity[setParameter name='system.TestProperty' value='1']"
$testProperty = "%system.TestProperty%"
Write-Host "system.TestProperty: $testProperty"
Write-Host "-------------"
What I'm getting:
-------------
system.TestProperty: 0
##teamcity[setParameter name='system.TestProperty' value='1']
system.TestProperty: 0
-------------
You wont see the parameter updated in the same script. If you split the check into another build step, you should see it there.

Teamcity 8- treat a build parameter as long or integer

Using teamCity 8.0.5.
As part of my builds cleanup I would like to automatically remove any build older than the current 5 builds. For eg if my build.number = 12 , try and remove build 6.
Unfortunately it seems that you can't cast %build.number%-6.
Using Teamcity how can you perform math on a build parameter?
I have tried
%build.number% -1 along with wrapping it in ()
%system.PreviousBuild% = \\server\path\Build%build.number%-6
my actual usage of this a command line post build event:
echo trying to remove directory %system.PreviousBuild%
IF EXIST %system.PreviousBuild% RD %system.PreviousBuild% /Q /S
result:
[09:19:09][Step 6/6] trying to remove director \server\path\Build11-6
-------------------------UPDATE---------------------------
the answer below led me to the following solution:
NOTE: The important part here is to cast the build.number as an integer.
using powershell source code build step
Using powershell for the entire command worked for me:
Set-Variable -Name previousBuild -Value (([int]%build.number%)-6).ToString()
Write-Output $previousBuild
Write-Output $env:PreviousBuildPath
Set-Variable -Name path -Value $env:PreviousBuildPath$previousBuild
Write-Output $path
if((Test-Path -path $path))
{
Remove-Item -Recurse -Force $path
}
set /a newBuildNumber=%build.number%-6
Then use %%newBuildNumber%% in your TC build script after the path.
\\server\path\Build%%newBuildNumber%%

Resources