create custom build definition in VSTS using script - visual-studio

I am creating CI/CD pipelines in VSTS using GIT repository.
I need to use the same steps from UI while creating build definition and release configuration for projects so i want to get off this repeating manual steps and create some automation around it so I don't have to do the same steps every time.
Can anyone tell me how it is possible using scripts or any other things?

To create build definitions you have two options:
Use the new YAML builds, which allows you to specify the whole build in a YAML file instead of UI elements.
Use the Build Definition REST API create the definition locally in json form and submit it to VSTS in a single transaction. There is a nice PowerShell library called "VSTeam" which wraps the REST API functions in powershell cmd-lets.
Another thing to look at would be the use of Task Groups, these allow you to abstract away a sequence of tasks and turn those into a single reusable task.

Related

Ability to expose test statistics for non-maven build steps in TeamCity

Normally (when used with Maven), in order to get the number of failed/passed test we can check TestOccurrences element in Teamcity REST API.
What would be the way to report and fetch test stats for non-maven steps (e.g. custom shell script)?
Is it possible to manually set TestOccurrences somehow, so all step types would report stats in the similar way? If not, how can we make custom stats available with Teamcity REST API?

Node (maven) to deploy the application to several environments

On Jelastic, I created a node for building an application (maven), there are several identical environments (NGINX + Spring Boot), the difference is in binding to its database and configured SSL.
The task is to ensure that after building the application (* .jar), deploy at the same time go to these several environments, how to implement it?
When editing a project, it is possible to specify only one environment, multi-selection is not provided.
it`s allowed to specify just one environment
We suggest creating a few environments using one Repository branch, and run updates by API https://docs.jelastic.com/api/#!/api/environment.Vcs-method-Update pushing whole code to VCS.
It's possible to use CloudScripting technology for attaching custom logic to onAfterBuildProject event and deploying the project to additional environments after build is complete. Please check this JPS as an example of the code syntax. Most likely you will need to use DeployProject API method.

How can I write to a Shared Resource of Custom Values in TeamCity?

TeamCity has a feature which is called "Shared Resources". This allows you to configure a set of custom values (i.e., URLs) which can be read from by the locking builds in order to properly share data and avoid resource conflicts. However, in my situation, the custom values (i.e., environment names) are not known yet. There is a separate build which will be able to create the environments. How can I have this build "write" into the custom values of the TeamCity Shared Resources so that the dependent builds can retrieve the most up-to-date values?
Currently parameters are not supported in TeamCity. Here is the related request https://youtrack.jetbrains.com/issue/TW-39174 you can vote for.

Get parameters from multiple build to one snapshot dependent build [teamcity]

In Teamcity 9.0.1 I have several builds, which ends up on similar steps, but with different parameters.
In fact, those are servicing steps, not needed by a build to conclude, that build is ok, but they are needed for service, so, currently, they are just running and consuming time.
What I am trying to reach - is move those steps to completely separate build, and invoke it on successful build end trigger. However, I could not figure out - how to pass changes parameters to these newly created build?
Snapshot dependency does not give me level of control I would like to have, as it requires me to define dependency parameters from specific build id, instead of reading them from build, which just ends.
Using artifact dependency by downloading .teamcity/properties/build.finish.gz!** fails with error:
Unknown archive type
and, actually, will oblige me to create additional xml parser
There's nothing built in to trigger builds with custom parameters on a finish-build trigger.
You will have to use the TeamCity REST API / HTTP endpoint to trigger the servicing build with custom parameters - you can pass them as key/value pairs using the following syntax (preferably use HTTPS of course):
http://testuser:testpassword#teamcity.jetbrains.com:8111/httpAuth/action.html?add2Queue=MyBuildConf&name=<full property name1>&value=<value1>&name=<full property name2>&value=<value2>
For further information see the docs.
Implementation-wise you should be able to do what you want in a few lines of powershell as a last step in the triggering build configs - they would have to pass the build parameters you want. If you use this in multiple build configurations I'd move this step into a common template or use a meta-runner.

Per-test sample data generation for load testing?

I have a set of load tests, each testing a specific section of Sharepoint site. How can I automate the generation of sample data prior to each test?
I know that load tests allow me to specify tests that are run before/after a specific virtual user's test mix, but those are meant for user-specific setup like logging on. I want to create sample data for all users.
I can put my setup code into the Team Build template, but that doesn't take into account whether the test using the sample data is in the test list being run or not. If I modify the test list, I would also need to modify the build template as well. I cannot put the setup code into a test that is run before the load test either, because load tests must be run with the .Net 4.0 framework while accessing Sharepoint's API requires 3.5.
I could rewrite my sample data generation logic with Powershell and start it from a .Net 4.0 unit test. Is it my best option or is there a more elegant way?
I think you question is more TeamBuild related than SharePoint. For short, the best way how to setup (and teardown) testdata in SharePoint is using PoSh in conjunction with the Microsoft.PowerShell.SharePoint SnapIn.
You can start your PowerShell scripts from Everywhere in TeamBuild. That's actually how I extend the default TeamBuild template. I've create a single custom build template, this template contains numerous PoSh hooks. While setting up a new project you can easily hook your scripts everywhere you need.
To be really independent from any .NET FX version you could create your sampledata using REST DataServices (ListData.svc)

Resources