Last active
February 3, 2021 11:51
-
-
Save heldner/bb5e485154beb2c5c8ad672ffe7a6c0e to your computer and use it in GitHub Desktop.
Jenkins fun in pipelines groovy
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
| // run command inside container with bypass aws creds | |
| def aws_cli_container ( | |
| String command, | |
| String verbose='none', | |
| String aws_cli_image='undefined', | |
| String aws_credentials_id='unknown' | |
| ) { | |
| docker.image(aws_cli_image).inside('--net=host') { | |
| withCredentials([[ | |
| $class: 'AmazonWebServicesCredentialsBinding', | |
| accessKeyVariable: 'AWS_ACCESS_KEY_ID', | |
| credentialsId: aws_credentials_id, | |
| secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) { | |
| if (verbose == 'returnStdout') { | |
| sh(script: "${command}", returnStdout: true) | |
| } else { | |
| sh "${command}" | |
| } | |
| } // withCredentials | |
| } // docker.image | |
| } // def | |
| // run command inside container with bypass ssh creds | |
| def ssh_docker_cmd ( | |
| String location = 'undefined', | |
| String hostname = 'undefined', | |
| String container = 'undefined', | |
| String command = 'undefined', | |
| String aws_cli_image = 'undefined', | |
| String jenkins_ssh_cred = 'empty' | |
| ) { | |
| docker.image(aws_cli_image).inside('--net=host') { | |
| sshagent (credentials: [jenkins_ssh_cred]) { | |
| sh "python scaling_conf exec \ | |
| --location ${location} \ | |
| --hostname ${hostname} \ | |
| --container ${container} \ | |
| --command '${command}'" | |
| } // sshagent | |
| } // docker.image | |
| } // def ssh_cmd | |
| // run docker container with ssh and ldap credentials | |
| def docker_ssh_ldap ( | |
| String docker_image = 'undefined_image', | |
| String jenkins_ssh_creds = 'empty', | |
| String command = 'undefined_cmd', | |
| String jenkins_ldap_cred = 'empty_ldap_cred' | |
| ) { | |
| echo "docker_image: ${docker_image}, \ | |
| jenkins_ssh_creds: ${jenkins_ssh_creds}, \ | |
| command: ${command}, \ | |
| jenkins_ldap_cred: ${jenkins_ldap_cred}" | |
| docker.image(docker_image).inside('--net=host --entrypoint=""', { | |
| withCredentials([ | |
| usernamePassword( | |
| credentialsId: jenkins_ldap_cred, | |
| usernameVariable: 'LDAP_USER', | |
| passwordVariable: 'LDAP_PASSWORD' | |
| ) | |
| ]) { | |
| sshagent (credentials: [jenkins_ssh_creds]) { | |
| sh "${command}" | |
| } // sshagent | |
| } // withCredentials | |
| }) // docker.image | |
| } // def docker_ssh_agent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment