Created
May 17, 2019 12:24
-
-
Save robot-o/0145496d764adf91adb5c993126cd357 to your computer and use it in GitHub Desktop.
Jenkinsfile Snippet to download a Github Release from a private repository via Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pipeline | |
| { | |
| environment | |
| { | |
| REPO_OWNER = "Acme" | |
| REPO_NAME = "Foo" | |
| ARTIFACT_NAME = "Dependency.zip" | |
| } | |
| stages | |
| { | |
| stage('Dependencies') | |
| { | |
| steps | |
| { | |
| withCredentials([ | |
| usernamePassword(credentialsId: 'github-jenkins', passwordVariable: 'GITHUB_PASSWORD', usernameVariable: 'GITHUB_USERNAME') | |
| ]) | |
| { | |
| // https://stackoverflow.com/a/27951845 | |
| // https://stackoverflow.com/a/45511507 | |
| powershell """ | |
| \$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$(\${var.GITHUB_USERNAME}):$(\${var.GITHUB_PASSWORD})")) | |
| \$basicAuthValue = "Basic \$encodedCreds" | |
| \$Headers = @{ | |
| Authorization = \$basicAuthValue | |
| } | |
| \$uri = Invoke-RestMethod -Uri 'https://api.github.com/repos/\${var.REPO_OWNER}/\${var.REPO_NAME}/releases/latest' -Headers $Headers | select -ExpandProperty assets | select -expand browser_download_url | |
| Invoke-WebRewquest \$uri -OutFile "\${var.ARTIFACT_NAME}" | |
| Expand-Archive ".\\\${var.ARTIFACT_NAME}" | |
| """ | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment