jenkins, automatic transmission errors pit deployment scp

Environment: centos7

Version: jenkins-2.176.3-1.1.noarch.rpm

Problem: After using the root account to install jenkins, configure automatic deployment, the project can not be completed package to the project server scp prompt (test server ssh port 22 by default changed after 6688)
Host Key Verification failed The Lost Connection.
[JENKINS] Archiving / opt / Jenkins /workspace/test-microservice/base-zuul/target/base-zuul-0.0.1-SNAPSHOT.jar to com.zjgf / base-zuul / 0.0.1-SNAPSHOT / base-zuul-0.0.1-SNAPSHOT.jar
[Test-microService] $ / bin / the bash /tmp/jenkins8821230735005579726.sh
Channel stopped
the Host Key the Verification failed.
Lost Connection
Upload Files Fail

Solution:
. 1, package installation RPM jenkins jenkins default to the default shell for the user:
jenkins: X: 992: 989: Jenkins Automation Server: / var / lib / jenkins: / bin / to false

2, modify the default the shell
Jenkins: X: 992: 988: Jenkins Automation Server: / var / lib / Jenkins: / bin / the bash

3, the user switches to jenkins
[node60 the root @ ~] #su - jenkins
the bash-4.2 $

4, solve the problem of variable
you can not see jenkins user variables, because when you install jenkins, jenkins jenkins user just created, and not to create a home directory. So when the system will not create a user, the user environment variables automatically copy files in / etc / skel directory to the user's home directory, it causes these files do not exist, -bash-4.2 # question arises.

5, modify jenkins user variable
The following command is (IMPORTANT Again, su - jenkins after re-execute the command) executed in the user switches to the next jenkins! (Now shows the user only -bash-4.2) panic this time, perform the following steps:

vim ~/.bash_profile

Execute the above command, even if no .bash_profile file, linux is automatically created.
Then add the phrase

export PS1='[\u@\h \W]\$'

: Wq (save and exit)

Then refresh .bash_profile file to work

source ~ / .bash_profile
and then you see the entry into force of the current variable

[jenkins@node60 root]$

Users can now see jenkins shell variable normal.

6, once again test
execution jenkins task again, or find an error, in Jenkins of course, if you use the sudo command in a script, the following error may appear:
sudo: NO and NO TTY Present askpass Program specified
that is because Jenkins server in the context of the time of executing the sudo command is incorrect, resulting in abnormal execution of this command.

7. Solution:
Switch to the root or administrator account

[root @ node60 ~] # visudo
plus line in the file
android.permission people in Group Commands All Wheel to RUN
% Wheel ALL = (ALL) ALL
Jenkins ALL = (ALL) the NOPASSWD: ALL

Jenkins perform the task again, found that there is an error, you need to add jenkins user's keys on the test server after investigation

cat /var/lib/jenkins/.ssh/id_rsa.pub

I'm prompted - -!
cat: /var/lib/jenkins/.ssh/id_rsa.pub: No such file or directory
and then
create jenkins user's public key file id_rsa.pub (su - jenkins jenkins the following command in the shell user !!!)

[jenkins@node60 root]$ ssh-keygen -t rsa

Enter all the way down, and then look at the generated key pair jenkins

[jenkins@node60 root]$ cat /var/lib/jenkins/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaWGfcK3 (too long, silently delete part) WEDv64dQ + oG / IN2lDQa / jenkins @ node60

Then copy the public key jenkins production, login test server, added to the test server deployments account ~ / .ssh / authorized_keys

[jenkins@test1 ~]$ vim ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaW0Mqv0xwKGfcK3WEDv645lPuhXXReY3jGdQ+onGwqym9G/IN2lDQa/ jenkins@node60
保存退出

8, test again
to re-edit jenkins task JOB * {It should be noted, specify the port number parameter -P and -p scp and ssh use of case-sensitive in the jenkins}
The following is the written test when I test scripts
· · ·
! / Bin / bash
upload path
UPLOAD = "/ opt / MSERVICE / File / the Upload"
scp -P 6688 /opt/jenkins/workspace/test-aaa-master/target/aaa-0.0.1-SNAPSHOT.jar Jenkins @ test1: $ UPLOAD ;
perform the test server update script
SSH -t -p 6688 Jenkins @ test1 'SH /home/jenkins/.sh/aaa.sh';
· · ·
So far, the problem is solved! Get away

Guess you like

Origin blog.51cto.com/13708014/2452586