Created
January 30, 2019 05:02
-
-
Save arehmandev/2c705ad22c1d16844b72ba9f5e579778 to your computer and use it in GitHub Desktop.
Jenkins pipeline fail at ssh-add
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
Hi if you're seeing this - you probably got stuck where I was: | |
The pipeline randomly fails at ssh-add? | |
Guess what the fix is - add a new line at the end of your ssh key stored in jenkins, absolutely stupid right. | |
Here's an example of pipeline: | |
def tagBuild(gitTag){ | |
// Required for setup of jenkins slave ssh daemon | |
tryAddKnownHost('github.com') | |
sshagent (credentials: ['arehmandev-git']) { | |
sh("git config --global user.email \"[email protected]\" && git config --global user.name \"arehmandev\"") | |
sh("git tag -a ${gitTag} -m \"[JENKINS] Deployment successful of tag ${gitTag}\" ") | |
sh("git push -u origin --tags") | |
} | |
} | |
void tryAddKnownHost(String hostUrl){ | |
// ssh-keygen -F ${hostUrl} will fail (in bash that means status code != 0) if ${hostUrl} is not yet a known host | |
def statusCode = sh script:"ssh-keygen -F ${hostUrl}", returnStatus:true | |
if(statusCode != 0){ | |
sh "mkdir -p ~/.ssh" | |
sh "ssh-keyscan ${hostUrl} >> ~/.ssh/known_hosts" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment