I'm deploying an app from git to a target server with Jenkins. I've set in my project a new Jenkinsfile which its stage('deploy') is pointing at the right machine. The conection would happen through SSH.
I've been reading for the deployment to succesfully run, both machines (git & target server) must know each others Host keys, which are stored in known_hosts at ~/.ssh/ . Therefore I connected through ssh from the git machine to the server (prompted if I wanted to continue establishing the connection, 'yes'):
checked the known_hosts file in git server to find the target server entry.
checked the known_hosts file at target server to find an entry, which looks like |1|KCIHm6...lo= ecdsa-sha2-nistp256 AAAA...(bla bla).
I think it's all set for Jenkins to be able to deploy on server, but everytime I build the project from Jenkins, the moment the first ssh deploy command is ran, the deployment fails with a 'Host key Verification failed' message. I can navigate through the target server no matter if I connect through my local machine or the git server, I've tried redoing the process but I can't really replicate the first connection.
Any suggestion is appreciated. Thanks in advance.
Create the ssh keys with jenkins user and restart jenkins.
su jenkins
ssh-keygen
ssh-copy-id destUser#destServer #Type the destUSer password
More info here
Related
I'm very new with Jenkins, and I'm trying to learn how to use it. I have setup the Jenkins on my small Windows-based server, and I have another server (raspberry) where I have initialized a small git project. When I try to add this git repository to the Jenkins, it can not connect to it no matter what. Here's what I have tried so far.
I can check, that the connection is working to the git server by using git ls-remote -h ssh://gitserver#192.168.50.152:22/home/gitserver/GitProject/.git command from any computer within the network, and I get a response after giving my password. I have saved this password as a "Username with password" -kind to Jenkins > Manage Jenkins > Credentials. Then, I have selected this from the Credentials drop down, but all I get is this error: "Failed to connect to repository : Error performing git command: git.exe ls-remote -h ssh://gitserver#192.168.50.152:22/home/gitserver/GitProject/.git HEAD"
Interesting part is, that if I try that command given with the "HEAD" at the end, I get just empty line, but no errors. Could this be an indicator to some kind of an issue? Here's a picture of the configuration. Am I doing something wrong? I have SSH authentication right now via password and ssh-public key. I have tried the SSH-public key as a credential, but no luck.
I'm very new to Jenkins, and just starting to learn, but I could not find an answer to this. Many articles were just pointing out how to connect to GitHub project, but I want to connect to this local project sitting on a raspberry pi, as an exercise.
Ok, the issue was with Jenkins and specifically with the SSH plugin it is using to connect. After updating everything, and Jenkins restarted, the connection is now working, and I can confirm this by clicking the "Build Now", and checking the Build log, Jenkins did fetch the info from the Raspberry server, and it is now sitting at the data-folder of this server!
So, for the rest of the people having this issue, try to update all plugins and then restart the Jenkins.
i have project jenkins to deploy to my remote server, my local machine and my remote server was connected with ssh but when i try to build job on jenkins, i am getting error like this
image
Login on your jenkins and then try to connect manually on the command line with ssh from jenkins to the remote server. Then approve the host key of the remote system. Run again your job. Then I think everything should be fine.
I have two servers (AWS-Ubuntu), one is for Devops in which I have installed Jenkins. And in another server I have a dev server. I have built code in the Jenkins server and need to transfer my built files to the dev server.
Added (jenkins)id_rsa.pub key to dev server, restarted SSH service:
cd ${WORKSPACE}/Angular
npm install
cd ${WORKSPACE}/node
npm install
cd ${WORKSPACE}/Angular
npm run build
scp -r /var/lib/jenkins/workspace/project123/Angular/dist/* ubuntu#172.31.14.41:/var/
I expect to transfer files from Jenkins instance to dev server but I am getting this error:
scp -r /var/lib/jenkins/workspace/project123/Angular/dist/openwifi ubuntu#172.31.45.66:/var/www/html/jenkinsdev/Angular/
Host key verification failed.
lost connection
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Host key verification failed error occurs when you try to ssh/scp using the wrong username.
username should be same which is used for establishing ssh.
If above does not help then check the ssh keys are not corrupted or changed for that user.
I have a Jenkins server setup with two jobs
first job polls the develop branch and builds the project on the jenkins server. i then have another job that polls the production branch this builds this branch on another jenkins slave which is the staging server. This job is configured so that on a successful build it should publish the artefacts over ssh to the production server.
All the SSh keys are setup and the staging server connects to production server but 0 files are transferred
using GIT_SSH to set credentials Bitbucket Repo
using .gitcredentials to set credentials
Checking out Revision 89874cc01a9f669df69817b1049b1ab98ecb19d3 (origin/Production)
SSH: Connecting from host [nginx-php-fastcgi]
SSH: Connecting with configuration [AmazonAWS] ...
SSH: Disconnecting configuration [AmazonAWS] ...
SSH: Transferred 0 file(s)
Finished: SUCCESS
I checked the staging workspace and files are being built there, just not sent to the prod server. Any suggestions??
i have also tried a different remove prefix as suggested bellow and here Jenkins transferring 0 files using publish over SSH plugin
You should remove /* from the Remove prefix line
Edit:
Your Source files cannot be outside of the job's workspace. If your files are in the root of workspace, just set it to * to transfer all workspace files, or **/* to include subdirectories. Else specify a pattern relative to ${WORKSPACE}.
Even adding a leading / will not escape that, as all it does is append that to workspace, in your case it becomes ${WORKSPACE}/var/www/workspace/opms-staging-server. Even using parent directory ../ will not work. This is for security concerns, else a job configurer could transfer private files off the Jenkins server.
If you need to get files from another job, you need to use Copy Artifacts build step. Tell me if that's your case, and I will explain further.
We're trying to setup Jenkins, but we are having a couple issues.
We have a "Jenkins Server" (Master) and have connected it to Fisheye. Jenkins is able to get the Git repo and run the tests.
Is there some kind of built in process for Jenkins to give it capabilites to SSH into a server and run commands like "git pull origin master" ?
Yes there is ssh capabilities in Jenkins. You can add a build step for either running SSH or sending files over SSH (you have to define target server in config). Theres also a post build plugin for sending artifacts over ssh which can be used to also execute remote commands.
I'd recommend a book by John Smart which covers Jenkins setup. Its at http://www.wakaleo.com/books/jenkins-the-definitive-guide
I think you want the SSH Plugin for Jenkins. This will let you define SSH servers in your global configuration, and then define commands to be run before and after the build.