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			
				}
			}
			
		  }
		}
      }	  
      
    }
}
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐