如何将 Jenkins 管道中的 Jenkins 配置文件复制到 Web 服务器
How to copy Jenkins config files in a jenkins pipeline to Web server
我在 Jenkins 配置文件中有一些 files.properties 需要在 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"
}
这很容易。您需要安装 Config File Provider Plugin 然后您可以通过访问 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'
}
我在 Jenkins 配置文件中有一些 files.properties 需要在 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"
}
这很容易。您需要安装 Config File Provider Plugin 然后您可以通过访问 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'
}