Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

credential variable in jenkins publish over ssh

This my Jenkins pipeline script. TOOL_CREDS_USR and TOOL_CREDS_PSW variables are not passed to the remote host. Since variables are null, my job hangs asking for username

I verified python command works, verified it by running directly on remote host with variables substituted

pipeline {
    environment {
        TOOL_CREDS = credentials('hello')
    }
    stages {
        stage('Deploy') {
            steps {
                echo 'Deploying....'
                sshPublisher(
                    continueOnError: false, 
                    failOnError: true,
                    publishers: [
                        sshPublisherDesc(
                            configName: "world",
                            sshTransfer(execCommand: 'python3 -m pip install --index-url https://$TOOL_CREDS_USR:$TOOL_CREDS_PSW@sample.com/repository/pypi-hosted/simple testpackage')
                            ],
                            verbose: true
                        )
                    ]
                )
            }
        }
    }
}

I tried ${} but that also fails. Please help


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had to use double quotes instead of single

sshTransfer(execCommand: "python3 -m pip install --index-url https://$TOOL_CREDS_USR:$TOOL_CREDS_PSW@sample.com/repository/pypi-hosted/simple testpackage")


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...