Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .vscode/cspell-devops-ext.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
vsix
tsbuildinfo
codepaths
azuretools
codepaths
LASTEXITCODE
tmrm
toolrunner
tsbuildinfo
vsix
1 change: 1 addition & 0 deletions ext/azuredevops/setupAzd/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.taskkey
index.js
tests/*.js
tests/*.log
48 changes: 37 additions & 11 deletions ext/azuredevops/setupAzd/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as task from 'azure-pipelines-task-lib/task'
import * as cp from 'child_process'
import * as toolRunner from 'azure-pipelines-task-lib/toolrunner'

export async function runMain(): Promise<void> {
try {
Expand All @@ -16,25 +16,51 @@ export async function runMain(): Promise<void> {
return
}
const version = task.getInput('version') || 'latest'
const windowsInstallScript = `powershell -c "$scriptPath = \\"$($env:TEMP)\\install-azd.ps1\\"; Invoke-RestMethod 'https://aka.ms/install-azd.ps1' -OutFile $scriptPath; . $scriptPath -Version '${version}' -Verbose:$true; Remove-Item $scriptPath"`
const linuxOrMacOSInstallScript = `curl -fsSL https://aka.ms/install-azd.sh | sudo bash -s -- --version ${version} --verbose`

console.log(`Installing azd version ${version} on ${os}.`)

if (os === 'win32') {
console.log(cp.execSync(windowsInstallScript).toString())
const powershellPath = task.which('powershell', true)
const powershell: toolRunner.ToolRunner = task.tool(powershellPath)
const installScript = `$scriptPath = "$($env:TEMP)\\install-azd.ps1"; Invoke-RestMethod 'https://aka.ms/install-azd.ps1' -OutFile $scriptPath; . $scriptPath -Version '${version}' -Verbose:$true; Remove-Item $scriptPath`
powershell.arg('-NoLogo')
powershell.arg('-NoProfile')
powershell.arg('-NonInteractive')
powershell.arg('-Command')
powershell.arg(installScript)

const installResult = await powershell.exec()
if (installResult !== 0) {
task.setResult(task.TaskResult.Failed, `Failed to install azd. Exit code: ${installResult}`)
return
}

// Add azd to PATH
task.setVariable('PATH', `${envPath};${localAppData}\\Programs\\Azure Dev CLI`)
} else {
console.log(cp.execSync(linuxOrMacOSInstallScript).toString())
}

// Run `azd version` to make sure if azd installation failed, it returns error on windows
if (os === 'win32') {
const azdVersion = `"${localAppData}\\Programs\\Azure Dev CLI\\azd.exe" version`
cp.execSync(azdVersion)
// Run `azd version` to make sure installation succeeded
const azdPath = `${localAppData}\\Programs\\Azure Dev CLI\\azd.exe`
const azd: toolRunner.ToolRunner = task.tool(azdPath)
azd.arg('version')
const versionResult = await azd.exec()
if (versionResult !== 0) {
task.setResult(task.TaskResult.Failed, `azd version check failed. Exit code: ${versionResult}`)
return
}
} else {
const bashPath = task.which('bash', true)
const bash: toolRunner.ToolRunner = task.tool(bashPath)
bash.arg('-c')
bash.arg(`curl -fsSL https://aka.ms/install-azd.sh | sudo bash -s -- --version ${version} --verbose`)

const installResult = await bash.exec()
Comment thread
vhvb1989 marked this conversation as resolved.
if (installResult !== 0) {
task.setResult(task.TaskResult.Failed, `Failed to install azd. Exit code: ${installResult}`)
return
}
}

console.log(`Successfully installed azd version ${version}.`)
} catch (err: any) {
task.setResult(task.TaskResult.Failed, err.message)
}
Expand Down
Loading
Loading