Jenkins pipeline 中读取yaml文件内容
server.yml文件内容serverConfig:name: testservers:#################### Test Environment ####################- deploymentName: testenvironment: release/testaddress: 192.168.0.2dir: /tmp/apps################
·
server.yml文件内容
serverConfig:
name: test
servers:
###################
# Test Environment #
###################
- deploymentName: test
environment: release/test
address: 192.168.0.2
dir: /tmp/apps
##################
# Prod Environment #
##################
- deploymentName: prod
environment: master
address: 192.168.0.3
dir: /tmp/apps
jenkinsfile
pipeline {
agent any
environment {
serversYaml = 'servers.yml'
}
stages {
stage('Read yamlfile') {
steps {
script{
def serverdatas = readYaml file : env.WORKSPACE + "/$serversYaml"
for (server in serverdatas.serverConfig.servers){
if (server.deploymentName != null && server.environment != null && server.address != null && server.dir != null ) {
echo "Deployment Name:" + server.deploymentName
echo "Deployment Environment:" + server.environment
echo "Deployment Address:" + server.address
echo "Deployment Dir:" + server.dir
}
}
}
}
}
}
}
更多推荐
已为社区贡献27条内容
所有评论(0)