Del ett | Det första problemet med VSTS är standardagentpoolerna, de är väldigt långsamma och lösningen är att sätta upp egna. Så varför inte? Det här är den första delen av hur du distribuerar dina nya VSTS-agenter från VSTS till Azure med hjälp av ARM mallar och Powershell DSC.

Vi börjar faktiskt i omvänd ordning genom att göra det sista steget i deploymenten först. Vid det här laget borde alla som arbetar och lever i molnet åtminstone veta vad ARM och DSC är. Jag vet inte men jag tycker personligen att DSC är det svårare att lära sig, så det kommer också att bli min utgångspunkt. I den här bloggen kommer vi att titta på en DSC som kommer att konfigurera din nyinstallerade VM för att vara en agent i VSTS-poolen och även installera node.js.

DSC

DSC filen har bara en konfiguration och alla nodnamn har samma konfiguration. Eftersom vi ska distribuera denna DSC via en Azure resource manager (ARM)-mall behöver vi inte någon komplicerad logik för vilken dator som får vilken konfiguration.

För att kunna kompilera denna DSC måste du installera två DSC-moduler

Find-Module xPSDesiredStateConfiguration | install-module
Find-Module PackageManagement -MaximumVersion ”1.1.7.0” | install-module


Configuration Main {

Param ( [string] $nodeName )
$AgentzipName = "vsts-agent-win-x64-2.127.0.zip"
$AgentDownloadUrl = ("https://vstsagentpackage.azureedge.net/agent/2.127.0/{0}" -f $AgentzipName)
$installsource = "C:\vstsAgent"
$PATToken = "[your vsts pat token]"
$poolName = "AzureAgents"
$VSTSUrl = "https://XXXXXXX.visualstudio.com"

Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -Module xPSDesiredStateConfiguration
Import-DSCResource -ModuleName PackageManagement -ModuleVersion "1.1.7.0"

Node $nodeName
 {
 File InstallFolder {
 #Create Installation folder
 Ensure = "Present"
 DestinationPath = $installsource
 Type = "Directory"
 }
 Script Chocolatey {
 SetScript = { 
 iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
 }
 TestScript = { 
 try{[boolean](cver all)} catch {[boolean]($fasle)}
 }
 GetScript = { @{ Result = "OK" } }
 }
 Script nodejs {
 SetScript = { 
 Start-Process -FilePath "chocolatey" -ArgumentList "feature enable -n allowGlobalConfirmation" -Wait
 start-process -FilePath "cinst" -ArgumentList "nodejs.install --force --safe" -Wait
 }
 TestScript = { 
 try{
 $res = (clist nodejs --localonly)
 -not ($res[1] -match "0 packages installed")
 } catch {[boolean]($fasle)}
 }
 GetScript = { @{ Result = "OK" } }
 dependsOn = "[Script]Chocolatey"
 } 
 Script DownloadAgentFiles {
 #Download agent
 SetScript = { 
 wget -OutFile "$using:installsource\$using:AgentzipName" -Uri $using:AgentDownloadUrl
 }
 TestScript = { 
 Test-Path "$using:installsource\$using:AgentzipName" 
 }
 GetScript = { @{ Result = "OK" } } 
 DependsOn = "[File]InstallFolder"
 }
 Archive UnzipAgentFiles {
 Destination = "${installsource}\agent"
 Path = "${installsource}\${AgentzipName}"
 DependsOn = @(
 "[Script]DownloadAgentFiles"
 )
 }
 Script ConfigureAgent {
 SetScript = {
 $Argument = "configure --unattended --agent $env:COMPUTERNAME --url $using:VSTSUrl --auth PAT --token $using:PATToken --pool `"$using:poolName`" --work d:\build --runAsService --windowsLogonAccount 'NT AUTHORITY\SYSTEM' --acceptTeeEula --replace"
 Write-Host "$using:installsource\agent\bin\Agent.Listener.exe"
 start-process -FilePath "$using:installsource\agent\bin\Agent.Listener.exe" -ArgumentList $Argument -Wait -RedirectStandardOutput o
 }
 TestScript = { 
 [boolean](get-service -DisplayName "VSTS*")
 }
 GetScript = { @{ Result = "OK" } } 
 DependsOn = @(
 "[Archive]UnzipAgentFiles",
 "[Script]nodejs"
 )
 }
 }
}

Gör följande:

DSC resurser

Låt oss gå igenom resurserna i DSC filen.

  • File InstallFolder – Vi ser till att det finns en mapp för att hålla installationsfilerna.
  • Script Chocolatey – Skriptet försöker köra cver (Chocolaty kommando) för att upptäcka om chocolatey installeras, om inte vi kör ett externt PS1 skript för att installera den..
  • Script nodejs – Ett annat skript som använder chocolatey för att installera node.js. För att kunna göra detta från en DSC måste vi först aktivera funktionen allowGlobalConfirmation. Annars fungerar inte –force –safe växlarna.
  • Script DownloadAgentFiles – Det här skriptet laddar ner installationsfilerna.
  • Archive UnzipAgentFiles – Packar upp ZIP filen med intallationsfilerna.
  • Script ConfigureAgent – Sista steget är att installera och konfigurera agenten.

The end

Grattis du är klar med denna del. I detta läga kan du manuellt köra DSC-konfigurationen på vilken Windows-server som helst för att konfigurera den för att vara ett VSTS-byggnadsagent.

Men det vi ska vi inte göra. Istället så kommer vi i mitt nästa inlägg skapar en ARM-mall och lägga till DSC-filen i den.

Relaterade inlägg

Vill du vara säker på att inte missa något

Som du märker brinner vi för att dela med oss av våra erfarenheter, nyttiga lärdomar och spaningar ut i exosfären. Se till att följa vårt nyhetsbrev eller vårt flöde på Linkedin så du inte missar något.

Hidden

This website uses cookies

Cookies ("cookies") consist of small text files. The text files contain data which is stored on your device. To be able to place some type of cookies we need your consent. We at Exobe AB, corporate identity number 556769-5605 use these types of cookies. To read more about which cookies we use and storage duration, click here to get to our cookiepolicy.

Manage your cookie-settings

Necessary cookies

Necessary cookies are cookies that need to be placed for fundamental functions on the website to work. Fundamental functions are for instance cookies that are needed for you to use menus and navigate the website.

Functional cookies

Functional cookies need to be placed for the website to perform in the way that you expect. For instance to remember which language you prefer, to know if you are logged in, to keep the website secure, remember login credentials or to enable sorting of products on the website in the way that you prefer.

Statistical cookies

To know how you interact with the website we place cookies to collect statistics. These cookies anonymize personal data.

Personalization cookies

In order to provide a better experiance we place cookies for your preferances

Ad measurement cookies

To be able to provide a better service and experience we place cookies to tailor marketing for you. Another purpose for this placement is to market products or services to you, give tailored offers or market and give recommendations on new concepts based on what you have bought from us previously.

Ad measurement user cookies

In order to show relevant ads we place cookies to tailor ads for you

Personalized ads cookies

To show relevant and personal ads we place cookies to provide unique offers that are tailored to your user data