如何将 jenkins 管道中的 Jenkins 配置文件复制到 Web 服务器

Cha*_*fot 2 configuration-files jenkins jenkins-pipeline

我在 Jenkins 配置文件中有一些 files.properties,我需要在 jenkins 管道期间将其复制到服务器。

管道代码或多或少如图所示,只是为了得到一个想法。如何添加一个步骤,在管道中的最后一步将 WAR 部署到服务器之后,从目标服务器上的 jenkins 复制此配置文件,例如:“sh Scp file.properties jenkins@destinationserver:/destination/path/file.properties ”

在此输入图像描述

code {
stage ('Code Checkout') {
            git branch: 'master',
                credentialsId: 'b346fbxxxxxxxxxxxxxxxxxxx',
                url: 'https://xxxxxxx@bitbucket.org/gr/code.git'

        }
stage ('Check Branch') { 
        sh 'git branch'
}

stage('Compile and Build WAR') {
        sh 'mvn clean compile war:war'

stage ('Deploy WAR to server') {
            sh "scp .war jenkins@serverIp:/var/lib/tomcat/.war"

        }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

tft*_*ftd 5

这很容易。您需要安装配置文件提供程序插件,然后可以通过访问生成适当的行htts://localhost/jenkins/pipeline-syntax/。从下拉列表中,您可以选择configFileProvider并填写表格的其余部分。

最终结果将是这样的:

configFileProvider(
    [configFile(fileId: 'maven-settings-or-a-UUID-to-your-config-file', variable: 'MAVEN_SETTINGS')]) {
    sh 'mvn -s $MAVEN_SETTINGS clean package'
}
Run Code Online (Sandbox Code Playgroud)