Available comma separated list from jenkins

I have an environment variable introduced Jenkinsas:

CUSTOMERS="foo,bar"

Now I need to iterate over these values. Is there a way to access these AS element values ​​in ansible?

Any help, including other suggestions on how to solve this problem, is appreciated.

+4
source share
1 answer

You can pass the environment variable to variable c --extra-vars, but this is only part of the solution, you need to get the value of the string in a data format that can be understood.

- Python ( ) script, JSON JSON vars --extra-vars "@customers.json" ( JSON ansible 1.3), . Ansible Variable.

import sys
import os
import json

DEFAULT_VAR="CUSTOMERS"

def var_to_json(var_name, list_sep = ','):
  var_dict = {var_name: os.environ[var_name].split(list_sep)}
  return json.dumps(var_dict)

var_name=DEFAULT_VAR
if len(sys.argv) > 1:
  var_name = sys.argv[1]
print var_to_json(var_name)

script ( ). , .

, , , . , , ( --extra-vars).

+1

Source: https://habr.com/ru/post/1536859/


All Articles