Publish over ssh plugin - can't copy build archive - jenkins

I have been struggling for hours with this thing and I have spent time reading some of the suggested similar questions but couldn't find a hint or solution.
I have a build job that creates a build archive. Then I have a separate deploy job that should take that archive and copy it over ssh to a remote environment. I am using the publish over ssh Jenkins plugin. Everything seems to go well except for the copy part. No files are copied to the remote location.
I get the following:
Started by user admin
Building in workspace /usr/lib/jenkins/workspace/preprod-deploy
SSH: Connecting from host [xxxxxx]
SSH: Connecting with configuration [xxxxxx] ...
SSH: Creating session: username [xxxxxx], hostname [xxxxxx], port [22]
SSH: Connecting session ...
SSH: Connected
SSH: Opening SFTP channel ...
SSH: SFTP channel open
SSH: Connecting SFTP channel ...
SSH: Connected
SSH: cd [/var/www/test_automation]
SSH: OK
SSH: Disconnecting configuration [xxxxxx] ...
SSH: Transferred 0 file(s)
Build step 'Send files or execute commands over SSH' changed build result to SUCCESS
Finished: SUCCESS
My guess is that there is something about the way I'm trying to configure the Source Files path (The base directory for this fileset is the workspace as per the tooltip).
My build archive is located in /usr/lib/jenkins/job/build/${BUILD_TO_DEPLOY}/artifact/*zip*/archive.zip where BUILD_TO_DEPLOY in a natural number corresponding to the build job.
According to the console output, the workspace of the deploy job is /usr/lib/jenkins/workspace/preprod-deploy
This is my configuration:
Ignore the exec command - that is just for testing purposes - but it works - it is successfully creating the txt file to the remote directory
Any ideas how can I overcome this?

Related

Not able to build jenkins pipeline

[EnvInject] - Loading node environment variables.
Building remotely on Dox2u_DockerRegistry in workspace /home/admin-vm/workspace/(Handler)(Document_Handler)(release_1.0.0.1)(dochandler_UAT)
[(Handler)(Document_Handler)(release_1.0.0.1)(dochandler_UAT)] $ /bin/sh -xe /tmp/jenkins6559820756424608510.sh
export BRANCH_NAME=release_1.0.0.1
/home/admin-vm/Data/workspace/Docker_Project/./pullcode_uat.sh
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Already on 'release/1.0.0.1'
Your branch is up to date with 'origin/release/1.0.0.1'.
Host key verification failed.
fatal: Could not read from remote repository.
I am trying to build project

I solved jenkins auth fail problem but i don't know why?

Background: My Jenkins is Deploy by docker at target server A.There is 4 intranet target servers(inner server) ABCD.Try to deploy code by plugin Public over SSH to target server C,When I try to establish a connection from jenkins to target server C,There is
jenkins.plugins.publish_over.BapPublisherException: Message [Auth fail]]
My Finnal solution: Put target server's id_rsa.pub to target server's authorized_keys.and i don't know why it works.
here is some of my trys:
put jenkins root's id_rsa.pub to target server root's authorized_keys
put jenkins jenkins's(user) id_rsa.pub to target server root's authorized_keys
create jenkins user at target server and repeat 1,2.this time put into target server's jenkins user.
when I try this,ssh and scp works correctly.but jenkins **Public over SSH ** can't.and now though I solved this but I want to know the reason. thanks for tolerate my gramma..

Unable to run command to remote machine via Jenkins

While trying to execute some shell command to a remote server from Jenkins, I am getting "Host key verification failed." error.
I have installed Jenkins in a docker on my MAC. Now from the Jenkins browser, I want to run some shell command to a remote server (which is accessible).
To do that I already added the server (10.206.y.z) in the configure page of jenkins (by providing hostname i.e. 10.206.y.z, username & the key generated in 10.206.y.z server in the SSH Servers section) & tested the connection. The connection test passed & then I saved the configuration.
For executing shell command on 10.206.y.z, I created a FreeStyle project & in the Execute Shell section I am passing ssh root1#10.206.y.z 'hostname'.
If I run the project by clicking 'Build Now', I am getting the below error & the build fails.
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/TestProject
[TestProject] $ /bin/sh -xe /tmp/jenkins4234161871485451783.sh
+ ssh root1#10.206.y.z hostname
Host key verification failed.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Any help please?
I think that the problem is the key. You are using the key generated in the destination machine (10.206.y.z)
You should use the key generated on the jenkins server and pass it to the destination server. For that you could use ssh-copy-id

Transfer to remote host using ssh (jenkins)

I have a compressed file in my jenkins workspace folder, I am trying to transfer that compressed file over ssh, but I got SSH: Transferred 0 file(s)
My Configurations are below-
Transfer set source file: my-files.zip
Remove Prefix:
Remote directory: /home/my-files
My Console Output:
Started by user Mizanur Rahman
SSH: Transferred 0 file(s)
Build step 'Send files or execute commands over SSH' changed build result to SUCCESS
Finished: SUCCESS
The first test would be to try and replicate that tranfer manually, from the server executing the job, with the user running the job.
On that server, try at least a:
ssh -Tv xxx#remote.com
That will confirm if you (as the user running the Jenkins job) actually establish an secure shell session. Replace xxx and remote.com by the remote user and remote server target for that session.

Jenkins Ansible plugin Permission denied (publickey,password) - failing to copy private key

I'm trying to use the Jenkins Ansible plugin to deploy a project. I figured this should be pretty easy as i'm pretty familiar with both Jenkins and Ansible. However, i'm having issues getting the Ansible command to successfully execute. I believe the problem lies in the use of the credentials. We have a jenkins user that owns the Jenkins execution process and we have a jenkins user setup on the machine being deployed to. We are using SSH keys and I have added the jenkins users private key to the Jenkins credential store and selected those in the Ansible configuration. However, when i run the job, this is the snippet of my output (replaced some information).
[my-job] $ ansible-playbook my-job.yml -i inventories/dev -l 1_2_3_4 -f 1 --private-key /tmp/ssh7229752594712048879.key -u jenkins --diff --vault-password-file ~/.vault-pass
PLAY [tag_ansible_groups_my_job] ***********************
TASK [setup] *******************************************************************
fatal: [1_2_3_4]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", "unreachable": true}
to retry, use: --limit #/data/jenkinsdata/workspace/my-job/my-job.retry
PLAY RECAP *********************************************************************
1_2_3_4 : ok=0 changed=0 unreachable=1 failed=0
FATAL: command execution failed
hudson.AbortException: Ansible playbook execution failed
at org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:227)
at org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:200)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1729)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:404)
ERROR: Ansible playbook execution failed
Finished: FAILURE
I've run the same command successfully from the Jenkins machine and it works just fine. The only difference was that I referenced the original SSH private key instead of the copied temporary key. To see if this was the issue, I decided to check the contents of the copied temporary SSH private key and the file was empty. I checked the file before the job finished executing as I am assuming it stays there for the life of the job and removed only after the job has finished executing. To verify this, I removed the use of credentials from the configuration and added in the private-key and user parameters pointing directly to the appropriate key and the job runs successfully.
[my-job] $ ansible-playbook my-job.yml -i inventories/dev -l 1_2_3_4 -f 1 --private-key ~/.ssh/id_rsa -u jenkins --diff --vault-password-file ~/.vault-pass
PLAY [tag_ansible_groups_my_job] ***********************
TASK [setup] *******************************************************************
ok: [1_2_3_4]
So, to me, it seems that Jenkins is failing to copy the SSH private key to the temporary file(s). I've tried with other SSH keys but still the same problem each time. I've tried specifying the private key in Jenkins credential store itself rather than specifying the location and that also did not work. I've checked the Jenkins logs and there is nothing that would indicate why the private SSH key would fail to copy to the /tmp directory.
I'd prefer not to reference the key directly in the additional parameters as this limits me to only keys located on that server. Any suggestions?
I found this solution at Edureka. It worked for me.
set "host_key_checking = False" in /etc/ansible/ansible.cfg
https://www.edureka.co/community/42595/not-able-connect-remote-host-via-jenkins-run-ansible-playbook

Resources