bash - Environment variables for docker-compose inside of Jenkins -
i've following setup:
jenkins environment running docker-compose need pass environment variables yml file:
sample docker-compose.yml
version: '2' services: logon_server: build: . image: my_server:0.0.1 ports: - "9200:9200" command: ${docker_cmd_exec} networks: - my_ntwrk networks: my_ntwrk:
when run following script shell prompt on mac, can pass different commands executed , works:
exec-tests.sh
#!/bin/bash chmod 755 docker/exec-*.sh # setup env variables export docker_cmd_exec=/ci_e2e.sh # optional: record current versions docker -v && docker-compose -v echo `whoami` echo `sudo -e -u admin printenv` # build, deploy , run e2e test cases sudo -e -u admin docker-compose --no-color --abort-on-container-exit
when run script inside of jenkins job, under 'build environment' -> 'execute shell' -> 'command', here image of i'm talking about:
i following error:
the docker_cmd_exec variable not set. defaulting blank string
i've tried running root , default user 'admin' jenkins run as. i've tried make environment variables inheritable, tried printing env's , looks good.
i can re-produce error on mac unsetting docker_cmd_exec cant figure out why happening in jenkins!
any appreciated!
thanks.
j
here solution:
docker script:
#!/bin/bash export compose_http_timeout=120 export docker_cmd_exec=/app/docker/ci_run.sh export docker_linked_cmd=/app/docker/ci_run.sh export docker_node_env=staging export docker_image_tag=${docker_image_tag:=staging} export docker_reload_db=${param_reload_db:=true} export docker_http_proxy='' # optional: record current versions docker -v && docker-compose -v # startup container(s) cat compose.yml | envsubst | docker-compose -f -
compose.yml file:
version: '2' services: app: build: . image: ${docker_image_tag} environment: - mongodb_host=mongodb - node_env=${docker_node_env} - http_proxy=${docker_http_proxy} ports: - "8000:8000" command: ${docker_cmd_exec} volumes: - /dev/shm:/dev/shm networks: - server-ntwk networks: server-ntwk:
the bash script , compose file in same directory:
./docker/exec-build.sh
Comments
Post a Comment