TFS Release Definition – Custom variables and values

Scenario – Sometimes we need to use some logic based data in a variable in Release definition task like datetime value. Example, You want to create backup folder with datetime folder to preserve the backups.

There is no direct way in TFS for achieving it. TFS does have some user defined variables that can be used for defined values but for such requirements in release, it does not have any.

To implement it, I did below steps –

  1. I defined variable in release definition and set the value to “none”. Example here is – backupfoldername and value is none.
  2. I added task for PowerShell script and added below Inline script to set the above defined variable with date time value –

$date= (Get-Date).ToString(‘MM.dd.yyyy-hhmmsstt’)

Write-Host “##vso[task.setvariable variable=backupfoldername]$date”

  1. Finally I added the release task where I wanted to use it and used it as $(variablename) like $(backupfoldername). It worked!
Advertisements

TFS–MAC build–Git error

I was trying to build one of my iOS based application in MAC from TFS. While trying to do so, I was getting error –

“error setting certificate verify locations:

  CAfile:/etc/ssl/certs/ca-xxxxx.crt

  CApath:/etc/ssl/certs/..”

Error screenshot is given below as well…

image

I was struggling to resolve it and I have not found much information on internet.

Finally, I am able to resolve it and wanted to share it here so that it can help all…

I looked into “system” and “global” git files and they were setup properly with all the required values of the certificates.

You can view these files using below commands –

System file – “git config –system –list

Global file – “git config –global –list

I have to give full access on the certs folder (/etc/ssl/certs) using the command –

sudo chmod –R 777 .

With it, it worked!

Important note – Many have given solution to turn off the SSLVerify which is absolutely not recommended way from security perspective.

How to publish build artifacts from iOS builds to Windows based drop location

The requirement is to publish the TFS build artifacts (output) of Xamarin.iOS or any iOS based application to the file share (drop location) based on windows environment.

As per the MS documentation, Publishing artifacts from a Linux or macOS agent to a file share (drop location) is not supported, we have to use some other way to achieve the same behavior.

Here is the option we have implemented and can be used –

1) In the build definition, add the task to publish the artifacts.  Select the Artifact Type as “Server” as shown below –

image

Note – This will save all the artifacts on the TFS database (SQL Server) and so it is recommended to have the retention policy in place to delete the unwanted artifacts from the TFS database.

2) Now, when you build the application using above publish option, once the application is build successfully, you can download all the Artifacts from the TFS web portal as shown below –

image

3) Now, if you want to have the build Artifact on some file share, you can not use the above task in iOS as said before that it is not supported for MAC agent. The workaround would be to have a release definition just to copy the build artifacts to the drop location with “Continuous Deployment” as a trigger so that as soon as build is done successfully in MAC, its build artifacts will be copied to the file share. This way you will have your build output in the file share just like the way you do for windows based agents.

image

a) Release definition creation screenshot

image

b) Release Definition with Task screenshot

TFS – Release automation – IIS based Websites

Here is the best practice for the release automation of IIS based applications –

Scenario 1 –

New Web applications –

Add below tasks in the given order –

  1. Copy task – Copy the website published code from build drop location to web server.
  2. Tokenization task – task for replacing required values in different environments.
  3. Any other requirement on the web folder like subfolder creation or folder permissions
  4. IIS Website creation task – Task to create website and its application pool. It also configures various required settings in IIS like authentication etc.
  5. Application pool start/stop task – Select the “Restart” option to restart the application pool.

Scenario 2 –

Upgrade Web applications –

Add below tasks in the given order –

  1. Application pool start/stop task – Select the “STOP” option to stop the application pool.
  2. Backup utility task – Take the backup of the existing web folder.
  3. Copy task – Copy the website updated published code from build drop location to web server.
  4. Tokenization task (If there are changes in config files)– task for replacing required values in different environments.
  5. Any other requirement on the web folder like subfolder creation or folder permissions
  6. Application pool start/stop task – Select the “START” option to start the application pool.

Please use below tasks for –

  1. IIS Website Application pool start/stop/restart (https://marketplace.visualstudio.com/items?itemName=mohdaslamansari.build-task)
  2. Folder permissions (https://marketplace.visualstudio.com/items?itemName=mohdaslamansari.FolderPermissions)
  3. Backup utility (https://marketplace.visualstudio.com/items?itemName=mohdaslamansari.backuputility)

clip_image001

 

            —–End of Article—–

Microsoft Marketplace Extension – Backup Utility

******Making Automation easy – Plug & Play Plugins********

In many releases, we get requirement to take the backup of all the files and folders of website before performing any updates on them. I have implemented this requirement using PowerShell in TFS. It needs source location from where to take the backup and the destination location where the backup will be placed.

To make it simple and easy to use, I created MS marketplace extension and published the same in the Microsoft marketplace.

It is now available publically to everyone to download and use.

Direct link – https://marketplace.visualstudio.com/items?itemName=mohdaslamansari.backuputility

Marketplace link – https://marketplace.visualstudio.com/

I have copied the sourcecode to GitHub for getting code contribution from public.

GitHub link – https://github.com/mdaslamansari/backuputility

clip_image001

clip_image001[4]

Task (UI) in release definition –

clip_image001[6]

Here is the PowerShell script at its core –

image

 

    —End of Article—-

My First Release Extension in Microsoft Marketplace

I am extremely happy to share with you that I have published my first release task extension (IIS Website Application Pool Start Stop) to the Microsoft Marketplace. It is now available publically to everyone to download and use as I am now verified published from MS.

Direct link – https://marketplace.visualstudio.com/items?itemName=mohdaslamansari.build-task

Marketplace link – https://marketplace.visualstudio.com/

I have copied the sourcecode to both GitHub for getting code contribution from public.

GitHub link – https://github.com/mdaslamansari/ApplicationPoolStartStop

clip_image001

Technology used –

Front-End (UI) – JSON (Extension manifest and Build task)

Back-End – PowerShell script

clip_image001[5]

 

Benefits of marketplace extensions –

1. With it, we don’t need to copy PowerShell scripts to each and every team projects. We just need to install extension on Team Collection level and it will be available in the available task list of all the team projects under it and you can then add it to the release definition.

2. By making it public, we have increased its reach and testing scope. People can contribute with code and testing results and it will make plugin robust.

TFS–RM–Website configurations

In TFS Release management automation, we are using “Manage IIS App” plugin to create/configure websites and their application pool.

clip_image002

Many times, depending on the application requirements, we need to do many website based configurations. They are documented below –

Requirement 1 – How to set “Enable 32-bit Application” to true in the application pool using TFS RM automation.

Solution – Using AppCmd.exe, it can be done by adding the below line in the advanced tab of above plugin –

set apppool /apppool.name:"$(WebURL)" /enable32bitapponwin64:true

Once executed successfully, it can be verified using the below screen (Application Pool -> Advanced Settings)

clip_image004

Requirement 2 – Enable/disable the below authentication methods –

1) Disable Anonymous Authentication – Using AppCmd.exe, it can be done by adding the below line in the advanced tab of above plugin –

unlock config /section:AnonymousAuthentication

set config "$(WebURL)" /section:AnonymousAuthentication /enabled:false

Note – $(WebURL) – It is variable for website URL.

2) Disable Basic Authentication – Using AppCmd.exe, it can be done by adding the below line in the advanced tab of above plugin –

unlock config /section:BasicAuthentication

set config "$(WebURL)" /section:BasicAuthentication /enabled:false

Note – $(WebURL) – It is variable for website URL.

3) Enable Windows Authentication – Using AppCmd.exe, it can be done by adding the below line in the advanced tab of above plugin –

unlock config /section:windowsAuthentication

set config "$(WebURL)" /section:windowsAuthentication /enabled:true

Note – $(WebURL) – It is variable for website URL.

Once executed successfully, it can be verified using the below screen (Website -> Authentication)

clip_image006

Requirement 3 – .Net Trust Levels needs to set to “Full”.

Solution –

Using AppCmd.exe, it can be done by adding the below line in the advanced tab of above plugin –

set config /commit:WEBROOT /section:trust /level:Full

Once executed successfully, it can be verified using the below screen (Website -> .Net Trust Levels)

clip_image008

Requirement 4 – Disable required SSL in Forms Authentication.

Solution –

Using AppCmd.exe, it can be done by adding the below line in the advanced tab of above plugin –

set config "$(WebURL)" /section:system.web/authentication /forms.requireSSL:false

Note –

$(WebURL) – It is variable for website URL.

To enable, change the value to true.

Once executed successfully, it can be verified using the below screen (Website -> Authentications -> Forms Authentication -> Edit)

clip_image010