JenkinsFile和管道中的sed命令

时间:2019-04-04 07:38:51

标签: jenkins jenkins-pipeline

我正在尝试运行JenkinsFile,该文件包含两个sed命令。但是当我整理文件时,我遇到了字符串插值的不同问题。

您知道如何在JenkinsFile中运行它吗? 提前致谢。

pipeline {
    agent any
    tools {nodejs "NodeJS 6.7.0"}
    stages {
        stage('checking out gitlab branch master') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/development']]])
            }
        }
        stage('executing release process') {
            environment {
                ARTIFACTORY_APIKEY = credentials('sandbox-gms-password')
            }
            steps {
                sh 'cp bowerrc.template .bowerrc'
                sh 'sed -i -e "s/username/zest-jenkins/g" .bowerrc'
                sh 'sed -i -e "s/password/${ARTIFACTORY_APIKEY}/g" .bowerrc'
                sh 'cat .bowerrc'
            }
        }
   }
}

1 个答案:

答案 0 :(得分:0)

将命令放在单个“ sh ”块中,请参考以下内容:-

pipeline {
agent any
tools {nodejs "NodeJS 6.7.0"}
stages {
    stage('checking out gitlab branch master') {
        steps {
            checkout([$class: 'GitSCM', branches: [[name: '*/development']]])
        }
    }
    stage('executing release process') {
        environment {
            ARTIFACTORY_APIKEY = credentials('sandbox-gms-password')
        }
        steps {
            sh '''
                  cp bowerrc.template .bowerrc
                  sed -i -e "s/username/zest-jenkins/g" .bowerrc
                  sed -i -e "s/password/${ARTIFACTORY_APIKEY}/g" .bowerrc
                  cat .bowerrc
               '''
        }
    }
   }
}