如何使用Jenkinsfile上的ssh发布和在Jenkinsfile上使用groovy SDL的scp?

java.lang.NoSuchMethodError:在步骤[archive,bat,build,catchError,checkout,deleteDir,dir,dockerFingerprintFrom,dockerFingerprintRun,echo,emailext,emailextrecipients,envVarsForTool,error,fileExists,getContext,git)中找不到这样的DSL方法’publishOverSsh’ ,input,isUnix,libraryResource,load,mail,milestone,node,parallel,properties,pwd,readFile,readTrusted,resolveScm,retry,script,sh,sleep,stage,stash,step,svn,timeout,timestamps,tool,unarchive ,unstash,waitUntil,withContext,withCredentials,withDockerContainer,withDockerRegistry,withDockerServer, 最佳答案 我使用Jen:groovy DSL在远程机器上使用SCP和SSH,使用Sh:shell脚本.

在此之前使用ssh-keygen在主机和Jenkins之间创建连接以进行无密码验证.

对于没有密码的SSH登录:

1)使用ssh-keygen使用以下命令创建ssh公钥和私钥:

$ssh-keygen

2)将公钥复制到.ssh / authorized_keys文件中的remote-host.

3)现在使用密码登录远程机器.

现在在Jenkinsfile脚本框中将包发布到远程服务器使用下面的命令:

sh 'scp -r ./tests ubuntu@HOST_IP/URL:/home/ubuntu/'

//to execute commands over ssh on remote host which is written in test-script.sh file

sh 'ssh ubuntu@HOST_IP/URL <  test-script.sh'

// For echo environmental variables BUILD_ID

echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"
点赞