Jenkins Pipeline SSH Publisher 环境变量、参数引用 要用双引号

Jenkins Pipeline SSH Publisher 环境变量、参数引用 要用双引号

在 Pipeline 脚本中,如果要使用变量,就必须使用  双引号

pipeline {
    agent any
    environment { 
        PROJECT_NAME='vipsoft' 
    }
    stages {
        stage('Docker Build 、Push Repository') {
            steps {
               echo " PROJECT_NAME => '${PROJECT_NAME}'"    
               sshPublisher(publishers: [sshPublisherDesc(configName: "DockerPublishSSH", transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: """
               pwd
               mkdir -p /opt/jenkins/${PROJECT_NAME}
               cd /opt/jenkins/${PROJECT_NAME}
               echo "/opt/jenkins/${PROJECT_NAME}"
               pwd

               echo 'COPY /target/${PROJECT_NAME}.jar /app/code/' > Dockerfile

            """, execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', 
            remoteDirectory: "${PROJECT_NAME}", remoteDirectorySDF: false, removePrefix: '', sourceFiles: "target//${PROJECT_NAME}.jar")], 
            usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])

               echo 'Docker Build、Push  SUCCESS'
            }
        }
    } 
}

 

posted @ 2022-11-07 11:59  VipSoft  阅读(2040)  评论(0编辑  收藏  举报