How to run webtests from a TFS build using powershell script - azure

I have a requirement to run webtests which are located in a particular folder through a build. Currently the tests are run from Visual Studio 2015.
Got to know to execute/use the below powershell script as a task. But clueless how to implement it. Is this powershell script enough?.
param
(
$tool = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe",
$path ,
$include = "*.webtest"
)
$web_tests = get-ChildItem -Path $paths -Recurse -Include $include
foreach ($item in $web_tests) {
$args += "/TestContainer:$item"
}
In this, how to pass in the $path value? Do I need to give the path of the directory which has all these 5 webtests?
Do I need a testsettings file to carry out this execution.
If I need a test settings file, do I need to copy all the webtests file to output directory?
All I get with this powershell is the below message
No test runs are available for this build. Enable automated tests in
your build definition by adding a task that runs tests for your test
framework of choice, such as the Visual Studio Test task. If you choose
to run tests using a custom task or runner, you can publish results
using the Publish Test Results task
Could any one please help me as in what I am missing here? Thanks for your time and help on this.

how to pass in the $path value?
When you use the powershell task to execute your powershell scripts, there is a option Arguments, which you could pass the value of $path:
Do I need to give the path of the directory which has all these 5
webtests?
Yes. In general, the .webtests file are all copied to the drops location, so the path always point to the drops location.
Do I need a testsettings file to carry out this execution.
The short answer is yes.
There is a great blog about how to Running WebTests as part of a VSTS VNext Release pipeline, you can check if it helps.
Hope this helps.

Related

Automate build SQL database projects through VS-CMD, other options?

I'm trying to automate build process for SSDT SQL Database Project.
I have a build script that i can run on VS command prompt to get dacpac file however my window agent doesn't have VS command prompt so i'm looking for other options here.
Please help.
use "Visual studio build" task which will automatically generate dacpac file for you for your database project.
If you pass the solution path to VS build task, it will take all the deployable project inside the solution and creates the necessary artifacts in a separate zip for each deployable project in a solution.
Reference: https://www.gatevnotes.com/continuous-integration-continuous-deployment-of-ssdt-projects-creating-azure-devops-pipelines/
You could use Command Line task to run a program from the command prompt. Azure Pipelines puts your inline script contents into a temporary batch file (.cmd) in order to run it. When you want to run a batch file from another batch file in Windows CMD, you must use the call command:
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/command-line?view=azure-devops&tabs=classic#running-batch-and-cmd-files
For example :
echo call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Tools\VsDevCmd.bat"

AzCopy (devops pipeline)is not recognized as the name of a cmdlet, function, script file, or operable program

I have a PowerShell script that works all the time when I use from my local machine (I have azCopy installed):
AzCopy `
/Source:C:\myfolder `
/Dest:https://mystorageaccount.blob.core.windows.net/mystoragecontainer `
/DestKey:<storage-account-access-key> `
/Pattern:"myfile.txt"
Using azure pipeline (Microsoft Hosted agent) this script fails with
"AzCopy.exe : The term 'AzCopy.exe' is not recognized as the name of a cmdlet, function, script file, or operable program."
I have tried different agents but still the same error.
Which agent I must use to use azCopy?
Am I missing the obvious?
Is there another way of doing this always using powershell?
To copy files to Azure with AzCpoy you can use build-in task Azure File Copy, you not need use PowerShell:
In addition, you can install the Microsoft Azure Build and Release Tasks extension that give you another task "Azure Copy File Extended" with more options.
Agree with Shayki Abramczyk, the Azcopy task he provided can also be used to achieve copy file. This is another way, you can consider give it a try :-)
Back to this issue. According to error message, I think it's because the missing SDK in hosted agent.
Until now, Microsoft does not install Azure.Storage.AzCopy in every hosted agent. So, the agent you used may does not support this.
We provide seven different agents for user use, but only Hosted VS2017, Hosted Windows 2019 with VS2019 and Hosted Ubuntu 1604 has been installed the SDK which support Azcopy.exe.
So, you can try with these three agents to execute your azcopy command with powershell.
Edit:
Becaues the executable file (azcopy.exe)is in local. So, where is your AzCopy.exe located? For me, it's C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy.
So, in script, you need to execute cd command to change directory to the file where AzCopy.exe located first.
cd “C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy”
Note: DO NOT lost double quote here, or you will get x86 is not recognized. If file path located not same with mine, just change file path with yours.
And then, because of using Powershell, you may need to use powershell syntax. Here is the complete format example which modify it based on your script:
$source="C:\MyFolder"
$dest="https://mystorageaccount.blob.core.windows.net/mystoragecontainer"
$pattern = "myfile.txt"
$destkey = <key>
cd “C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy”
$azcopy = .\AzCopy.exe /Source:$source /Dest:$dest /DestKey: $destkey
/Pattern: $pattern
Please try with it.
For people like me, landing to this thread because they have this error by calling AZ copy in a PS Script, it's confirmed AZ Copy in not installed in Last (VM2019) version of Windows Hosted. But according to MS, binary is present in the Image, so you don't have to install it, but just to use the right path.
For more information about packages installed (or saved) on VM, you can check this Git Repo

Jenkins build Visual Studio Solution with Different Configuration

Hi I have a visual studio solution which has been configured in Jenkins. And it's building successfully in debug configuration. How ever I need to change the build configuration to Release or another different one.
So How can I configure Jenkins to select the configuration to build?
If you are using the MSBuild plugin, try adding the configuration flag on the "Command Line Arguments" section:
/p:Configuration=Release
If you are simply building from command line script (batch, powershell, etc), add the above flag there..
What I do, is create a generic job for build process which receives a parameter called "BUILD_CONFIGURATION" from the parent job which triggers it.
And I then reference it in the flag as a variable:
/p:Configuration=${BUILD_CONFIGURATION}

CruiseControl.NET MSTest not overwriting trx file

I'm trying to show the results of visual studio unit tests within CruiseControl. Here is the relevant part of my config:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\mstest.exe
C:\Build\Test\TestCases\
/testcontainer:H4Test\bin\debug\H4Test.dll /runconfig:localtestrun.Testrunconfig /resultsfile:H4Test\H4Results.trx
900
C:\Build\Test\TestCases\H4Test\H4Results.trx
The issue is that the H4Results.trx can only be created once, so every subsequent run just shows the results of the first run of the test cases. I need to specify the name so that I can do the merge command. How do I get this working?
Thanks,
Justin
Here's the answer, creating a bat file to delete the .trx each run:
http://blogs.blackmarble.co.uk/blogs/bm-bloggers/archive/2006/06/14/5255.aspx

Cruisecontrol.net nant results different from non-cc.net

I've a nant script that builds a VS2008 solution. When I run it myself by typing 'nant' in the command line all the correct DLLs are copied to the respective bin directories. But when Cruisecontrol performs the CI build no DLLs are copied to the bin directories.
Any ideas what's causing this?
Your problem, dear Mr. Flibble, is that you have specified "test" as the target in the cc.net config which is overrigind the default target (build) that gets executed when executing nant from the commandline.
Very probably there is something in your environment not in the Cruise Control environment. Add something in the CruiseControl build (like setting verbose on nant) and confirm you have the same paths set up.

Resources