Only use https to access teamcity server

Read this blog before you do my steps: http://paulstovell.com/blog/teamcity-ssl-on-windows-with-redirect-from-http

If the steps in the article didn’t help you, then try with my solution 🙂

1. In the connector, only use port 443 as a connector, this mean, you have to remote the connector for port 80

Teamcity443

2. In IIS -> Default Website (port 80), change “http redirect” to your https

HttpRedirect

Add teamcity.khetkhet.se in the internal dns (otherwise, you need to add it in the host file 172.27.89.113 teamcity.khetkhet.se).

It is pointing to the internal ip of machinename: 172.27.89.113

Change the internal dns to point to the external ip of the server


The certificate above has expired, and we have to replace it with new one. Follow this guide to solve it: http://paulstovell.com/blog/teamcity-ssl-on-windows-with-redirect-from-http

Some highlights:

In C:/Teamcity/conf/server.xml

2019-07-16_0958

In C:/Teamcity/conf/web.xml

2019-07-16_0959

Remember to open firewall port for 443.

Trigger teamcity run using javascript

Read the following code:

function connectingToSP() {
(function () {
var cors_api_host = ‘cors-anywhere.herokuapp.com’;
var cors_api_url = ‘https://’ + cors_api_host + ‘/’;
var slice = [].slice;
var origin = window.location.protocol + ‘//’ + window.location.host;
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function () {
var args = slice.call(arguments);
var targetOrigin = /^https?:\/\/([^\/]+)/i.exec(args[1]);
if (targetOrigin && targetOrigin[0].toLowerCase() !== origin &&
targetOrigin[1] !== cors_api_host) {
args[1] = cors_api_url + args[1];
}
return open.apply(this, args);
};
})();

var spURL = “https://yourteamcityhere/httpAuth/app/rest/builds”;

function getWWWAuthentication() {
var dfd = $.Deferred();

$.ajax({
url: spURL,
beforeSend: function(xhr) {
xhr.setRequestHeader(“Authorization”, “Basic ” + btoa(“username:password”));
},
type: ‘GET’,
dataType: ‘json’,
contentType: ‘application/json’,
processData: false,
success: function (data) {
alert(JSON.stringify(data));
dfd.resolve(data);
},
error: function(){
dfd.resolve(null);
}
});

return dfd.promise();
}

getWWWAuthentication()
.then();
}

connectingToSP();

Config TeamCity to run UI Test on NUnit Framework

For Agent machine

  1. Install Firefox
  2. Install NUnit Adapter on Visual Studio
  3. Add Firefox path to PATH

For coding

8

For Teamcity

1. Specific agent machine for compatibility2

2. In Artifact paths of General Settings: Copy everything from Release folder to another folder (optional)3

3. Define steps

3.1 Restore packages4

3.2 Build and Package Test solution5.PNG

/p:Configuration=Release /p:Platform=”Any CPU” /p:FrameworkPathOverride=”C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1″ /p:DeployOnBuild=true;PublishProfile=PackageToZip

3.3 Update Test parameters6.PNG

echo Username::%Test.Username% > %system.teamcity.build.checkoutDir%\Test\UnitTest.CodeBase\bin\Release\Parameters.txt
echo Password::%Test.Password% >> %system.teamcity.build.checkoutDir%\Test\UnitTest.CodeBase\bin\Release\Parameters.txt
echo SiteUrl::%Test.SiteUrl% >> %system.teamcity.build.checkoutDir%\Test\UnitTest.CodeBase\bin\Release\Parameters.txt

3.4 Run UI Test in command line

Old

%system.teamcity.build.checkoutDir%\OmniaTest\UnitTest.CodeBase\bin\Release\TestWindow\vsTest.console.exe “%system.teamcity.build.checkoutDir%\OmniaTest\UnitTest.CodeBase\bin\Release\UnitTest.CodeBase.dll” /UseVsixExtensions:true

New

Turn on read/write  permission for current user on: E:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow

vsTest.console.exe %~dp0/UnitTest.CodeBase.dll /TestAdapterPath:”your packages path\Test\Dev\packages”

 

4. Define Parameters7

5. Turn on console mode in the build agent

cs stop TCBuildAgent
ping 192.0.2.2 -n 1 -w 10000 > nul

C:\BuildAgent\bin\agent.bat start