Skip to content

Instantly share code, notes, and snippets.

@lupupaulsv
Last active August 31, 2021 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lupupaulsv/db7af7bcc3346bcacf86bd32d2863ab8 to your computer and use it in GitHub Desktop.
Save lupupaulsv/db7af7bcc3346bcacf86bd32d2863ab8 to your computer and use it in GitHub Desktop.
pipeline {
environment {
LANG = "C.UTF-8"
}
agent {
docker {
image 'centos:7'
args '-p 2222:22 -v --privileged '
}
}
stages {
stage("PushToGitHub") {
steps {
sh """yum install -y git
echo 'root:test' | chpasswd
git config --global user.email "example@example.com"
git config --global user.name "Automation"
git config --global push.default simple
"""
sshagent (credentials:['plupu-github']) {
sh """
git checkout staging
git pull --rebase
"""
}
}
}
}
post {
failure {
input 'Build failed, SSH is open at port: 2222'
}
}
}
[Pipeline] sshagent
[ssh-agent] Using credentials git (plupu-github)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Exec ssh-agent (binary ssh-agent on a remote machine)
$ docker exec 8dc329784a3517c27eff3b9bcefec4cf1cc296d6c13ff26fdcd417f669df1e5f ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-BxsIqboprJDx/agent.104
SSH_AGENT_PID=109
Running ssh-add (command line suppressed)
Identity added: /var/lib/jenkins/workspace/web-staging@tmp/private_key_4159778290407912291.key (/var/lib/jenkins/workspace/web-staging@tmp/private_key_4159778290407912291.key)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
+ git checkout staging
Previous HEAD position was eee3853... Amended
Switched to branch 'staging'
+ git pull --rebase
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[Pipeline] }
$ docker exec --env ******** --env ******** 8dc329784a3517c27eff3b9bcefec4cf1cc296d6c13ff26fdcd417f669df1e5f ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 109 killed;
[ssh-agent] Stopped.
[Pipeline] // sshagent
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] input
Build failed, SSH is open at port: 2222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment