Skip to content

Commit 4a586e7

Browse files
committed
Adding api token support.
1 parent d406ef7 commit 4a586e7

File tree

3 files changed

+191
-157
lines changed

3 files changed

+191
-157
lines changed

tasks/detect-task/detect-task.ps1

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Import-Module $PSScriptRoot\lib\argument-parser.ps1
88

99
######################SETTINGS#######################
1010

11-
$TaskVersion = "1.0.4"; #Automatically Updated
11+
$TaskVersion = "1.1.0"; #Automatically Updated
1212
Write-Host ("Detect for TFS Version {0}" -f $TaskVersion)
1313

1414
#Support all TLS protocols.
@@ -25,11 +25,7 @@ Write-Host "Getting inputs from VSTS."
2525

2626
#Get Hub Information
2727

28-
$Service = (Get-VstsInput -Name BlackDuckHubService -Require)
29-
$ServiceEndpoint = Get-VstsEndpoint -Name $Service
30-
$HubUrl = $ServiceEndpoint.Url
31-
$HubUsername = $ServiceEndpoint.auth.parameters.username
32-
$HubPassword = $ServiceEndpoint.auth.parameters.password
28+
$Service = (Get-VstsInput -Name BlackDuckHubService -Default "")
3329

3430
#Get Proxy Information
3531

@@ -67,11 +63,27 @@ $Env:DETECT_EXIT_CODE_PASSTHRU = "1" #Prevent detect from exiting the session.
6763
$Env:DETECT_JAR_PATH = $DetectFolder
6864
$Env:DETECT_LATEST_RELEASE_VERSION = $DetectVersion
6965

70-
Write-Host "Setting detect hub parameters"
71-
#We don't want to pass these to the powershell script as arguments or they will get printed.
72-
${Env:blackduck.hub.url} = $HubUrl
73-
${Env:blackduck.hub.username} = $HubUsername
74-
${Env:blackduck.hub.password} = $HubPassword
66+
if ([string]::IsNullOrEmpty($Service)){
67+
Write-Host ("No service selected.");
68+
}else{
69+
Write-Host ("Setting black duck service properties.");
70+
71+
$ServiceEndpoint = Get-VstsEndpoint -Name $Service
72+
$HubUrl = $ServiceEndpoint.Url
73+
74+
$ApiToken = $ServiceEndpoint.auth.parameters.apitoken
75+
$HubUsername = $ServiceEndpoint.auth.parameters.username
76+
$HubPassword = $ServiceEndpoint.auth.parameters.password
77+
78+
#We don't want to pass these to the powershell script as arguments or they will get printed.
79+
${Env:blackduck.url} = $HubUrl
80+
${Env:blackduck.apitoken} = $ApiToken
81+
${Env:blackduck.username} = $HubUsername
82+
${Env:blackduck.password} = $HubPassword
83+
}
84+
85+
Write-Host ("Setting tfs properties.");
86+
7587
${Env:detect.phone.home.passthrough.detect.for.tfs.version} = $TaskVersion
7688

7789
if ($UseProxy -eq $true){
@@ -80,10 +92,10 @@ if ($UseProxy -eq $true){
8092
$ProxyPort = $ProxyUri.Port
8193
Write-Host ("Parsed Proxy Host: {0}" -f $ProxyHost)
8294
Write-Host ("Parsed Proxy Port: {0}" -f $ProxyPort)
83-
${Env:blackduck.hub.proxy.host} = $ProxyHost
84-
${Env:blackduck.hub.proxy.port} = $ProxyPort
85-
${Env:blackduck.hub.proxy.password} = $ProxyUsername
86-
${Env:blackduck.hub.proxy.username} = $ProxyPassword
95+
${Env:blackduck.proxy.host} = $ProxyHost
96+
${Env:blackduck.proxy.port} = $ProxyPort
97+
${Env:blackduck.proxy.password} = $ProxyUsername
98+
${Env:blackduck.proxy.username} = $ProxyPassword
8799
}
88100

89101
#Ask our lib to parse the string into arguments

0 commit comments

Comments
 (0)