简体   繁体   中英

Execute external bash script inside GitLab-ci Docker build

I would like to execute an external (on the local machine) bash script from gitlab-ci.yml which uses the docker:stable image. I would like to execute startup.sh located outside the gitlab docker image. Is this possible or are there better options?

gitlab-ci.yaml

image: docker:stable

#Build script

variables:
  CI_DEBUG_TRACE: "true"
  DOCKER_DRIVER: overlay

before_script:
  - docker --version

build:
  services:
  - docker:dind
  script:
    - docker build --no-cache -t <tag> .
    - docker login -u root -p <pass> <registry>
    - docker tag ...
    - docker push ...
    - echo "build completed"
  stage: build
  tags:
    - <tag>

deploy_staging:
  stage: deploy
  script:
    - ./sh startup.sh

bash script

#!/bin/bash

docker login -u root -p <pass>
docker pull <image>
docker-compose up -d

I am not sure if this is the best practice for your use-case but the simple way to share files with an image is to add volume and share this code to the image by editing your config.toml file .

add this line to config.toml under [runners.docker]

volumes = ["/cache", path to startup.sh :/root/scripts"]

and then inside your.gilatb.yml

    deploy_staging:
      stage: deploy
      script:
        - chmod +x /root/scripts/startup.sh     
        - ./sh /root/scripts/startup.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM