Jenkins使用WithCreentials在远程linux机器上运行脚本
我想运行一些从Jenkins客户机到远程linux机器(remotehost.domain.com)的脚本。这里我想使用'withCrendentials'函数。我尝试了下面的代码,但没有按预期工作。如何做到这一点?请帮忙Jenkins使用WithCreentials在远程linux机器上运行脚本,jenkins,jenkins-pipeline,jenkins-groovy,Jenkins,Jenkins Pipeline,Jenkins Groovy,我想运行一些从Jenkins客户机到远程linux机器(remotehost.domain.com)的脚本。这里我想使用'withCrendentials'函数。我尝试了下面的代码,但没有按预期工作。如何做到这一点?请帮忙 #!/usr/bin/env groovy def remote = [:] remote.name = 'Linux' remote.allowAnyHosts = true pipeline { agent { label 'jenkinsClie
#!/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")
}
}
}
}
}
尝试添加以首先在jenkins设置中添加凭据记录。设置凭据时,您应该能够为凭据添加一个名称,即“github测试”。然后在这里的withCredentials中,引用记录“github测试”