github.com/bshelton229/agent@v3.5.4+incompatible/install.ps1 (about)

     1  $installDir = "C:\buildkite-agent"
     2  $arch = "amd64"
     3  $beta = $env:buildkiteAgentBeta
     4  $token = $env:buildkiteAgentToken
     5  $tags = $env:buildkiteAgentTags
     6  
     7  if ([string]::IsNullOrEmpty($token)) {
     8      throw "No token specified, set `$env:buildkiteAgentToken"
     9  }
    10  
    11  $ErrorActionPreference = "Stop"
    12  
    13  Write-Host "
    14    _           _ _     _ _    _ _                                _
    15   | |         (_) |   | | |  (_) |                              | |
    16   | |__  _   _ _| | __| | | ___| |_ ___    __ _  __ _  ___ _ __ | |_
    17   | '_ \| | | | | |/ _\` | |/ / | __/ _ \  / _\` |/ _\` |/ _ \ '_ \| __|
    18   | |_) | |_| | | | (_| |   <| | ||  __/ | (_| | (_| |  __/ | | | |_
    19   |_.__/ \__,_|_|_|\__,_|_|\_\_|\__\___|  \__,_|\__, |\___|_| |_|\__|
    20                                                  __/ |
    21                                                 |___/"
    22  
    23  ## Verify we are elevated
    24  ## https://superuser.com/questions/749243/detect-if-powershell-is-running-as-administrator
    25  
    26  $elevated = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
    27  if($elevated -eq $false) {
    28      throw "In order to install services, please run this script elevated."
    29  }
    30  
    31  $releaseInfoUrl = "https://buildkite.com/agent/releases/latest?platform=windows&arch=$arch"
    32  if($beta) {
    33      $releaseInfoUrl = $releaseInfoUrl + "&prerelease=true"
    34  }
    35  
    36  Write-Host "Finding latest release"
    37  
    38  $resp = Invoke-WebRequest -Uri "$releaseInfoUrl" -UseBasicParsing -Method GET
    39  
    40  $releaseInfo = @{}
    41  foreach ($line in $resp.Content.Split("`n")) {
    42      $info = $line -split "="
    43      $releaseInfo.add($info[0],$info[1])
    44  }
    45  
    46  # Github requires TLS1.2
    47  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    48  
    49  Write-Host "Downloading $($releaseInfo.url)"
    50  Invoke-WebRequest -Uri $releaseInfo.url -OutFile 'buildkite-agent.zip'
    51  
    52  Write-Host 'Expanding buildkite-agent.zip'
    53  Expand-Archive -Force -Path buildkite-agent.zip -DestinationPath $installDir
    54  Remove-Item buildkite-agent.zip -Force
    55  
    56  $binDir = Join-Path $installDir "bin"
    57  if (![System.IO.Directory]::Exists($binDir)) {[void][System.IO.Directory]::CreateDirectory($binDir)}
    58  
    59  Write-Host 'Expanding buildkite-agent.exe into bin'
    60  Join-Path $installDir "buildkite-agent.exe" | Move-item -Destination $binDir -Force
    61  
    62  Write-Host 'Updating PATH'
    63  $env:PATH = "${binDir};" + $env:PATH
    64  [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)
    65  
    66  # Verify it worked
    67  buildkite-agent --version
    68  
    69  Write-Host "Updating configuration in ${installDir}\buildkite-agent.cfg"
    70  $buildkiteAgentCfgTemplate = Get-Content "${installDir}\buildkite-agent.cfg"
    71  $buildkiteAgentCfgTemplate = $buildkiteAgentCfgTemplate -replace 'token="xxx"', ('token="{0}"' -f $token.Trim())
    72  
    73  if (![string]::IsNullOrEmpty($tags)) {
    74      $buildkiteAgentCfgTemplate = $buildkiteAgentCfgTemplate -replace '# tags="key1=val2,key2=val2"', ('tags="{0}"' -f $tags)
    75  }
    76  
    77  [System.IO.File]::WriteAllLines("${installDir}\buildkite-agent.cfg", $buildkiteAgentCfgTemplate);
    78  
    79  Write-Host "Successfully installed to $installDir
    80  
    81  You can now start the agent!
    82  
    83    ${binDir}\buildkite-agent.exe start
    84  
    85  For docs, help and support:
    86  
    87    https://buildkite.com/docs/agent/v3
    88  
    89  Happy building! <3
    90  "