简体   繁体   English

jenkins 在 ssh 代理插件 sh 命令中获取管道环境变量

[英]jenkins get pipeline environment variable in ssh agent plugin sh command

I am trying to get environment variable declared in pipeline unfortunately i am not getting the pipeline environment variable in ssh agent shell command.我正在尝试获取在管道中声明的环境变量不幸的是我没有在 ssh 代理 shell 命令中获取管道环境变量。

I am trying to get environment variable declared in pipeline unfortunately i am not getting the pipeline environment variable in ssh agent shell command.我正在尝试获取在管道中声明的环境变量不幸的是我没有在 ssh 代理 shell 命令中获取管道环境变量。

Please find the code below:请在下面找到代码:

#!groovy
library 'reference-pipeline'


pipeline{
    agent { 
        label 'Weblogic||Tomcat'
    }

    environment{
        HostName='test.prod.com'
        sshserver="ssh -o StrictHostKeyChecking=no user@${HostName}"

        SERVER_ADDRESS='192.25.58.201'
        CONFIG='PRODUCTION'

    }
    stages 
    {
        stage("Check TLA version") 
        {
         steps{
            script{
                    sshagent(credentials : ['SSH_Credentials']) {
                        sh """
                        set -e
                        $sshserver << "EOF"
                         
                        echo "Configuration:$CONFIG"  // output "Configuration: " should be "Configuration:production"
                        echo " Server:$SERVER_ADDRESS" // output "Server: " should be "Server: 192.25.58.201"
                        echo " Server Host  :  $hostname" // output "server host: testgood"
                        echo "started"
                        '`git describe`'
                        echo "ended"
                        
                         cd /var/lib/ubuntu/test-srv/current

                        server_version="`git describe`"
                        echo "Current server version:  $server_version"
                        if [[ $server_version != *'1.0.0_Release'* ]]; then
                            echo "Error: The underlying server version is not 1.0.0_Release Release. Exiting ..."
                            exit 1
                        fi
    EOF                   
                        """


                      
                    }
                }
            }
        }
        
    }
    post {
        always {
                cleanWs()
            }
    }
}

Instead of:代替:

echo "Configuration:$CONFIG"

try:尝试:

echo "Configuration: ${env.CONFIG}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jenkins 声明式管道 ssh 代理插件 - Jenkins declarative pipeline ssh agent plugin 在流水线 SH 脚本中使用 Jenkins 环境变量 - Using Jenkins Environment Variable in Pipeline SH script Jenkins 管道代理使用环境变量 - Jenkins pipeline agent to use environment variable 在同一 Jenkins 管道中的下一个新代理中,如何在上一个结束的代理中获取自定义环境变量(使用 AWS 代码提交 Jenkins 项目) - At next new agent in the same Jenkins Pipeline, how to get customized environment variable in last ended agent (using AWS Code commit Jenkins project) 在 Pipeline Bat 命令中引用 Jenkins 环境变量 - Reference Jenkins Environment Variable in Pipeline Bat Command 如何在Jenkins声明性管道的代理部分中使用环境变量? - How to use an environment variable in the agent section of a Jenkins Declarative Pipeline? Jenkins Pipeline 脚本 sh 命令中的变量值 - Variable value inside Jenkins Pipeline script sh command 如何在 jenkins 管道 groovy 脚本中向 sh aws 命令插入变量? - How to insert variable to sh aws command in a jenkins pipeline groovy script? 如何访问 jenkins 管道阶段变量以获取连接的 sh 命令 - How to access jenkins pipeline stage variable for concated sh command Jenkins 管道:如何用变量替换部分 sh 命令 arg - Jenkins Pipeline: How to replace part of a sh command arg with a variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM