差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

tech:perl:yaml [2021/08/28 13:41] – 建立 jonathantech:perl:yaml [2021/08/28 20:40] (目前版本) jonathan
行 3: 行 3:
   * Ubuntu : <cli>sudo apt-get install libyaml-perl</cli>   * Ubuntu : <cli>sudo apt-get install libyaml-perl</cli>
  
 +===== Example =====
 +<code perl>
 +#!/usr/bin/perl
 +
 +use YAML::Loader;
 +use Data::Dumper;
 +
 +# Load a YAML stream of 3 YAML documents into Perl data structures.
 +my $loader = YAML::Loader->new;
 +my $hash = $loader->load(<<'...');
 +stages:
 +- name: Deploy--DB
 +  iiidevops: deployed-environments
 +  steps:
 +  - applyAppConfig:
 +      answers:
 +        db.gui: true
 +        db.name: todo_db
 +        db.password: templatePassword
 +        db.tag: 13
 +        db.type: postgresql
 +        db.username: iiidevops
 +        git.branch: ${CICD_GIT_BRANCH}
 +        git.commitID: ${CICD_GIT_COMMIT}
 +        git.repoName: ${CICD_GIT_REPO_NAME}
 +        git.url: ${CICD_GIT_URL}
 +      catalogTemplate: cattle-global-data:iii-dev-charts3-db
 +      name: ${CICD_GIT_REPO_NAME}-${CICD_GIT_BRANCH}-db
 +      targetNamespace: ${CICD_GIT_REPO_NAME}
 +      version: 0.3.1
 +  when:
 +    branch:
 +      include:
 +      - master
 +
 +- name: Deploy--Wait DB deployment
 +  iiidevops: deployed-environments
 +  steps:
 +  - env:
 +      deploy_name: ${CICD_GIT_REPO_NAME}-${CICD_GIT_BRANCH}-db
 +      max_wait: 128
 +      namespace: ${CICD_GIT_REPO_NAME}
 +    envFrom:
 +    - sourceKey: API_TOKEN
 +      sourceName: pipeline-api-key
 +      targetKey: rancher_api_token
 +    - sourceKey: rancher-url
 +      sourceName: rancher
 +      targetKey: rancher_url
 +    runScriptConfig:
 +      image: iiiorg/deployment-waiter:0.0.2
 +      shellScript: rancher login ${rancher_url} -t ${rancher_api_token} --skip-verify; bash /app/run.sh
 +  when:
 +    branch:
 +      include:
 +      - master
 +...
 +
 +# Dump the Perl data structures back into YAML.
 +#print Dumper($hash);
 +
 +$i=0;
 +while ($hash->{'stages'}[$i]) {
 +        $hash_t = $hash->{'stages'}[$i];
 +        #print Dumper($hash_t);
 +        print("----- ".$hash_t->{'name'}." ---\n");
 +        print("\t ".$hash_t->{'iiidevops'}." \n");
 +        $i++;
 +}
 +</code>執行結果<cli>
 +~$ perl example.pl
 +----- Deploy--DB ---
 +         deployed-environments
 +----- Deploy--Wait DB deployment ---
 +         deployed-environments
 +~$
 +</cli>
  
 ===== 參考網址 ===== ===== 參考網址 =====
  • tech/perl/yaml.1630129300.txt.gz
  • 上一次變更: 2021/08/28 13:41
  • jonathan