Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Support provider and extraArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Feb 28, 2020
1 parent 31755dc commit 19a64e9
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
27 changes: 27 additions & 0 deletions src/test/groovy/InstallToolsStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.junit.Before
import org.junit.Test
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertTrue

class InstallToolsStepTests extends ApmBasePipelineTest {
Expand Down Expand Up @@ -54,6 +55,20 @@ class InstallToolsStepTests extends ApmBasePipelineTest {
assertJobStatusFailure()
}

@Test
void test_with_unsupported_provider_in_windows() throws Exception {
def script = loadScript(scriptName)
helper.registerAllowedMethod('isUnix', [], { false })
try {
script.installTool([ tool: 'python3', provider: 'foo', version: '1' ])
} catch(e) {
// NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', 'installTools: unsupported provider'))
assertJobStatusFailure()
}

@Test
void test_install_tool_in_linux() throws Exception {
def script = loadScript(scriptName)
Expand Down Expand Up @@ -88,4 +103,16 @@ class InstallToolsStepTests extends ApmBasePipelineTest {
assertTrue(assertMethodCallContainsPattern('withEnv', 'VERSION=z.y.x, TOOL=bar'))
assertJobStatusSuccess()
}

@Test
void test_install_tool_in_windows_with_all_flags() throws Exception {
def script = loadScript(scriptName)
helper.registerAllowedMethod('isUnix', [], { false })
script.installTool([ tool: 'foo', version: 'x.y.z', provider: 'choco', extraArgs: "--foo 'bar' 'foo'" ])
printCallStack()
assertTrue(assertMethodCallContainsPattern('powershell', 'Install foo:x.y.z'))
assertTrue(assertMethodCallContainsPattern('powershell', """script=choco install foo --no-progress -y --version 'x.y.z' "--foo 'bar' 'foo'" """))
assertFalse(assertMethodCallContainsPattern('powershell', 'script=.\\install-with-choco.ps1'))
assertJobStatusSuccess()
}
}
22 changes: 22 additions & 0 deletions vars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ Sample return:
]
}
```

## githubRepoGetUserPermission
Get a user's permission level on a Github repo.

Expand Down Expand Up @@ -646,6 +647,27 @@ def body = httpRequest(url: "https://www.google.com", method: "GET", headers: ["
def body = httpRequest(url: "https://duckduckgo.com", method: "POST", headers: ["User-Agent": "dummy"], data: "q=value&other=value")
```

## installTools
This step will install the list of tools

```
installTools([ [ tool: 'python3', version: '3.5'] ])
installTools([ [ tool: 'python3', version: '3.5'], [tool: 'nodejs', version: '12.0' ] ])
```

```
installTools([
[ tool: 'visualstudio2019enterprise', version: '16.4.0.0', provider: 'choco', extraArgs: '--package-parameters "--includeRecommended"' ]
])
```


* tool: The name of the tool to be installed for the default package manager. Mandatory.
* version: The version of the tool to be installated. Mandatory.
* provider: The provider to be used for installing the tools. Default behaviour
will detect then one available for the OS. Optional.
* extraArgs: Allow to use some extra args to extend the provider. Optional.

## isCommentTrigger
Check it the build was triggered by a comment in GitHub and the user is an Elastic user.
it stores the comment owner username in the BUILD_CAUSE_USER environment variable and the
Expand Down
29 changes: 22 additions & 7 deletions vars/installTools.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
installTools([ [ tool: 'python3', version: '3.5'] ])
installTools([ [ tool: 'python3', version: '3.5'], [tool: 'nodejs', version: '12.0' ] ])
installTools([
[ tool: 'visualstudio2019enterprise', version: '16.4.0.0', provider: 'choco', extraArgs: '--package-parameters "--includeRecommended"' ]
])
*/

def call(List params = []){
Expand All @@ -34,14 +38,25 @@ def call(List params = []){
private installTool(Map params) {
def tool = params.containsKey('tool') ? params.tool : error('installTools: missing tool param.')
def version = params.containsKey('version') ? params.version : error('installTools: missing version param.')
def provider = params.containsKey('provider') ? params.provider : ''
def extraArgs = params.containsKey('extraArgs') ? params.extraArgs : ''

if(isUnix()) {
error 'TBD: install in linux'
} else {
def scriptFile = 'install-with-choco.ps1'
def resourceContent = libraryResource('scripts/install-with-choco.ps1')
writeFile file: scriptFile, text: resourceContent
withEnv(["VERSION=${version}", "TOOL=${tool}"]) {
powershell label: "Install ${tool}:${version}", script: ".\\${scriptFile}"
}
}
switch (provider) {
case 'choco':
powershell label: "Install ${tool}:${version}", script: """choco install ${tool} --no-progress -y --version '${version}' "${extraArgs}" """
break
case '':
def scriptFile = 'install-with-choco.ps1'
def resourceContent = libraryResource('scripts/install-with-choco.ps1')
writeFile file: scriptFile, text: resourceContent
withEnv(["VERSION=${version}", "TOOL=${tool}"]) {
powershell label: "Install ${tool}:${version}", script: ".\\${scriptFile}"
}
break
default:
error 'installTools: unsupported provider'
}
}
11 changes: 10 additions & 1 deletion vars/installTools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ installTools([ [ tool: 'python3', version: '3.5'] ])
installTools([ [ tool: 'python3', version: '3.5'], [tool: 'nodejs', version: '12.0' ] ])
```

```
installTools([
[ tool: 'visualstudio2019enterprise', version: '16.4.0.0', provider: 'choco', extraArgs: '--package-parameters "--includeRecommended"' ]
])
```


* tool: The name of the tool to be installed for the default package manager. Mandatory
* tool: The name of the tool to be installed for the default package manager. Mandatory.
* version: The version of the tool to be installated. Mandatory.
* provider: The provider to be used for installing the tools. Default behaviour
will detect then one available for the OS. Optional.
* extraArgs: Allow to use some extra args to extend the provider. Optional.

0 comments on commit 19a64e9

Please sign in to comment.