Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In the sample script below, please update lines 1 to 4 before executing it.

Info

Lines 8-9, 22-23 and 26-27 contain the ` characters allowing multi-line commands in Powershell scripts, to increase readiness of this sample code.

Code Block
languagepowershell
$sldomain="mycompany.sealights.co" 
$slagenttoken="$(AgentToken.Sandbox)"
$APP_NAME="MyApplication"
$APP_NAMESPACE="CalculatorServer.Controllers"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-Output "Download the Sealights DotNet agent version set in settings..." 
$agentversion = ((iwr -Uri https://$($sldomain)/api/v2/agents/dotnet/recommended -Headers @{'Accept' = 'application/json'; 'Authorization' = "Bearer $($slagenttoken)"}).Content `
                          | ConvertFrom-Json | Select-Object agent).agent.version
iwr -OutFile sealights-dotnet-agent.zip -Uri http://agents.sealights.co/SL.DotNet/SL.DotNet-$($agentversion).zip
Expand-Archive .\sealights-dotnet-agent.zip -DestinationPath SL.DotNet -Force
Write-Output "Sealights agent version used is: $(Get-Content .\SL.DotNet\version.txt)" 

#Retrieve the same name of target branch as reported in Sealights Dashboard by removing the uncecessary prefix
$PR_TARGET_BRANCH="$(System.PullRequest.TargetBranch)".Replace("refs/heads/","")
#Retrieve the last Commit Hash from the PR branch and not the one from the ADO local Merge (via git log history)
$PR_LAST_COMMIT=$(git log -2 --format=%H).Split(" ")[1]
$PR_NUMBER="$(System.PullRequest.PullRequestId)"
$REPO_URL="$(System.PullRequest.SourceRepositoryURI)"

Write-Output "`n*** Create PR BSID ***"
.\SL.DotNet\x64\SL.DotNet.exe prConfig --appName $APP_NAME --pullRequestNumber $PR_NUMBER --targetBranch $PR_TARGET_BRANCH --latestCommit $PR_LAST_COMMIT --repositoryUrl $REPO_URL `
        --includeNamespace $APP_NAMESPACE --buildSessionIdFile $(Build.ArtifactStagingDirectory)\SealightsBuildSessionId.txt --token $($slagenttoken) --logEnabled true --logAppendConsole true --ignoreCertificateErrors true

Write-Output "`n*** Prepare for MSBuild ***"
.\SL.DotNet\x64\SL.DotNet.exe prepareForMsBuild --buildSessionIdFile $(Build.ArtifactStagingDirectory)\SealightsBuildSessionId.txt --workspacePath $(Build.Repository.LocalPath)\src `
        --baseDir  $(Build.Repository.LocalPath) --ignoreGeneratedCode true --debugMode true --logEnabled true --logAppendConsole true --ignoreCertificateErrors true --token $($slagenttoken) --scm git --scmProvider vsts