Skip to content

Instantly share code, notes, and snippets.

@renizgo
Last active June 4, 2019 15:36
Show Gist options
  • Save renizgo/8bcd531e94c2975fade81de1735d4706 to your computer and use it in GitHub Desktop.
Save renizgo/8bcd531e94c2975fade81de1735d4706 to your computer and use it in GitHub Desktop.
Login on Kubernetes with credentials Jenkinsfile
node {
def creds
stage('Sandbox') {
withCredentials([usernamePassword(credentialsId: 'my-creds', passwordVariable: 'C_PASS', usernameVariable: 'C_USER')]) {
creds = "\nUser: ${C_USER}\nPassword: ${C_PASS}\n"
}
println creds
}
}
node {
def creds
stage('Iniciando o Deploy') {
withCredentials([usernamePassword(credentialsId: 'admin_kube_dev', passwordVariable: 'C_PASS', usernameVariable: 'C_USER')]) {
creds = "${C_PASS}"
println creds
sh '''
echo 'Inciando o deploy'
echo "Passowrd: ${C_PASS}"
kubectl config set-credentials k8s.dev.renato.io --username=admin --password=${C_PASS}
kubectl config set-cluster k8s.dev.renato.io --insecure-skip-tls-verify=true --server=https://api.k8s.dev.renato.io
kubectl config set-context k8s.dev.renato.io --user=k8s.dev.renato.io --namespace=default --cluster=k8s.dev.renato.io
kubectl config use-context k8s.dev.renato.io
kubectl get pods -n jenkins
'''
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment