Skip to content

Commit 9892a21

Browse files
author
BDS-AD\jpiscitelli
committed
Proxy fixes. Embedded script update. Bump to 1.0.4
1 parent 2f10861 commit 9892a21

File tree

4 files changed

+69
-12
lines changed

4 files changed

+69
-12
lines changed

tasks/detect-task/detect-task.ps1

Lines changed: 26 additions & 6 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.3"; #Automatically Updated
11+
$TaskVersion = "1.0.4"; #Automatically Updated
1212
Write-Host ("Detect for TFS Version {0}" -f $TaskVersion)
1313

1414
#Support all TLS protocols.
@@ -33,11 +33,19 @@ $HubPassword = $ServiceEndpoint.auth.parameters.password
3333

3434
#Get Proxy Information
3535

36-
$Service = (Get-VstsInput -Name BlackDuckHubService -Require)
37-
$ServiceEndpoint = Get-VstsEndpoint -Name $Service
38-
$HubUrl = $ServiceEndpoint.Url
39-
$HubUsername = $ServiceEndpoint.auth.parameters.username
40-
$HubPassword = $ServiceEndpoint.auth.parameters.password
36+
$ProxyService = (Get-VstsInput -Name BlackDuckHubProxyService -Default "")
37+
$UseProxy = $false;
38+
if ([string]::IsNullOrEmpty($ProxyService)){
39+
Write-Host ("No proxy service selected.");
40+
}else{
41+
Write-Host ("Found proxy service.");
42+
$UseProxy = $true;
43+
$ProxyServiceEndpoint = Get-VstsEndpoint -Name $ProxyService
44+
$ProxyUrl = $ProxyServiceEndpoint.Url
45+
$ProxyServiceEndpoint.Url | Get-Member
46+
$ProxyUsername = $ProxyServiceEndpoint.auth.parameters.username
47+
$ProxyPassword = $ProxyServiceEndpoint.auth.parameters.password
48+
}
4149

4250
#Get Other Input
4351

@@ -66,6 +74,18 @@ ${Env:blackduck.hub.username} = $HubUsername
6674
${Env:blackduck.hub.password} = $HubPassword
6775
${Env:detect.phone.home.passthrough.detect.for.tfs.version} = $TaskVersion
6876

77+
if ($UseProxy -eq $true){
78+
$ProxyUri = [System.Uri] $ProxyUrl
79+
$ProxyHost = ("{0}://{1}" -f $ProxyUri.Scheme, $ProxyUri.Host)
80+
$ProxyPort = $ProxyUri.Port
81+
Write-Host ("Parsed Proxy Host: {0}" -f $ProxyHost)
82+
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
87+
}
88+
6989
#Ask our lib to parse the string into arguments
7090
Write-Host "Parsing additional arguments"
7191
$DetectArguments = New-Object System.Collections.ArrayList

tasks/detect-task/lib/detect.ps1

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $EnvHomeTempFolder = "$HOME\tmp"
4444
# heap size, you would set DETECT_JAVA_OPTS=-Xmx6G.
4545
#$DetectJavaOpts = Get-EnvironmentVariable -Key "DETECT_JAVA_OPTS" -DefaultValue "";
4646

47-
$Version = "0.6.2"
47+
$Version = "0.6.4"
4848

4949
$DetectReleaseBaseUrl = "https://test-repo.blackducksoftware.com/artifactory/bds-integrations-release/com/blackducksoftware/integration/hub-detect"
5050
$DetectSnapshotBaseUrl = "https://test-repo.blackducksoftware.com/artifactory/bds-integrations-snapshot/com/blackducksoftware/integration/hub-detect"
@@ -95,6 +95,11 @@ function Get-ProxyInfo () {
9595
try {
9696

9797
$ProxyHost = ${Env:blackduck.hub.proxy.host};
98+
99+
if ([string]::IsNullOrEmpty($ProxyHost)){
100+
$ProxyHost = ${BLACKDUCK_HUB_PROXY_HOST};
101+
}
102+
98103
if ([string]::IsNullOrEmpty($ProxyHost)){
99104
Write-Host "Skipping proxy, no host found."
100105
}else{
@@ -104,6 +109,10 @@ function Get-ProxyInfo () {
104109

105110
$ProxyPort = ${Env:blackduck.hub.proxy.port};
106111

112+
if ([string]::IsNullOrEmpty($ProxyPort)){
113+
$ProxyPort = ${Env:BLACKDUCK_HUB_PROXY_PORT};
114+
}
115+
107116
if ([string]::IsNullOrEmpty($ProxyPort)){
108117
Write-Host "No proxy port found."
109118
}else{
@@ -116,6 +125,14 @@ function Get-ProxyInfo () {
116125
#Handle credentials
117126
$ProxyUsername = ${Env:blackduck.hub.proxy.username};
118127
$ProxyPassword = ${Env:blackduck.hub.proxy.password};
128+
129+
if ([string]::IsNullOrEmpty($ProxyUsername)){
130+
$ProxyUsername = ${BLACKDUCK_HUB_PROXY_USERNAME};
131+
}
132+
133+
if ([string]::IsNullOrEmpty($ProxyPassword)){
134+
$ProxyPassword = ${BLACKDUCK_HUB_PROXY_PASSWORD};
135+
}
119136

120137
if ([string]::IsNullOrEmpty($ProxyPassword) -or [string]::IsNullOrEmpty($ProxyUsername)){
121138
Write-Host "No proxy credentials found."
@@ -127,11 +144,11 @@ function Get-ProxyInfo () {
127144
$ProxyInfoProperties.Credentials = $ProxyCredentials;
128145
}
129146

130-
Write-Host "Succesfully setup proxy."
147+
Write-Host "Successfully setup proxy."
131148
}
132149

133150
} catch [Exception] {
134-
Write-Host ("An exception occured setting up the proxy, will continue but will not use a proxy.")
151+
Write-Host ("An exception occurred setting up the proxy, will continue but will not use a proxy.")
135152
Write-Host (" Reason: {0}" -f $_.Exception.GetType().FullName);
136153
Write-Host (" Reason: {0}" -f $_.Exception.Message);
137154
Write-Host (" Reason: {0}" -f $_.Exception.StackTrace);
@@ -143,7 +160,27 @@ function Get-ProxyInfo () {
143160
}
144161

145162
function Invoke-WebRequestWrapper($Url, $ProxyInfo, $DownloadLocation = $null) {
146-
return Invoke-WebRequest $Url -UseBasicParsing -OutFile $DownloadLocation -Proxy $ProxyInfo.Uri -ProxyCredential $ProxyInfo.Credentials
163+
$parameters = @{}
164+
try {
165+
if ($DownloadLocation -ne $null){
166+
$parameters.Add("OutFile", $DownloadLocation);
167+
}
168+
if ($ProxyInfo -ne $null){
169+
if ($ProxyInfo.Uri -ne $null){
170+
$parameters.Add("Proxy", $ProxyInfo.Uri);
171+
}
172+
if ($ProxyInfo.Credentials -ne $null){
173+
$parameters.Add("ProxyCredential",$ProxyInfo.Credentials);
174+
}
175+
}
176+
}catch [Exception] {
177+
Write-Host ("An exception occurred setting additional properties on web request.")
178+
Write-Host (" Reason: {0}" -f $_.Exception.GetType().FullName);
179+
Write-Host (" Reason: {0}" -f $_.Exception.Message);
180+
Write-Host (" Reason: {0}" -f $_.Exception.StackTrace);
181+
}
182+
183+
return Invoke-WebRequest $Url -UseBasicParsing @parameters
147184
}
148185

149186
function Get-DetectSnapshotJar ($DetectFolder, $DetectVersion, $ProxyInfo) {

tasks/detect-task/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": "1",
1515
"Minor": "0",
16-
"Patch": "3"
16+
"Patch": "4"
1717
},
1818
"minimumAgentVersion": "1.95.0",
1919
"instanceNameFormat": "Run Black Duck Detect for your build $(message)",

vsts-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifestVersion": 1,
33
"id": "detect-for-tfs",
4-
"version": "1.0.3",
4+
"version": "1.0.4",
55
"name": "Black Duck Detect",
66
"publisher": "black-duck-software",
77
"public": true,

0 commit comments

Comments
 (0)