如何解决Jenkins使用withCrentials在远程Linux机器上运行脚本
我想从Jenkins客户端计算机到远程linux计算机(remotehost.domain.com)运行一些脚本。在这里,我想利用“ withCrendentials”功能。我尝试了下面的代码,但未按预期工作。如何实现呢?请帮忙。
#!/usr/bin/env groovy
def remote = [:]
remote.name = 'Linux'
remote.allowAnyHosts = true
pipeline {
agent {
label 'jenkinsClient'
}
environment
{
WORK_DIR = "/scratch/testuser/perlcode"
}
stages {
stage('Test credentials3')
{
steps
{
withCredentials([
usernamePassword(credentials: 'bff7499c-9a65-4c80-87b2-3ed8e299bfa9',usernameVariable: USER,passwordVariable: PWD)
])
script
{
echo "$PWD"
remote.host = 'remotehost.domain.com'
remote.user = 'testuser'
remote.password = ${PWD}
def var1 = sshCommand remote: remote,command: "hostname;pwd"
echo "$var1"
//sleep(time:5,unit:"SECONDS")
}
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。