Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins使用WithCreentials在远程linux机器上运行脚本_Jenkins_Jenkins Pipeline_Jenkins Groovy - Fatal编程技术网

Jenkins使用WithCreentials在远程linux机器上运行脚本

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

我想运行一些从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")
                            }
                            
                }
            }
    }   
    
    }       

尝试添加以首先在jenkins设置中添加凭据记录。设置凭据时,您应该能够为凭据添加一个名称,即“github测试”。然后在这里的withCredentials中,引用记录“github测试”