Rabbani_
Rabbani_

Reputation: 470

gitlab CICD pipeline not triggering deploy stage

GitLab CICD pipeline triggering deploy stage after test stage. I am trying to learn CICD with GitLab with a very simple node js application. I have pushed the docker image to the docker hub and then I am trying to test. if the test success it will be pulled on the server and restarted with the latest code.

image: docker:24.0.5
services:
  - docker:24.0.5-dind

stages:
  - test
  - deploy

variables:
  CONTAINER_TEST_IMAGE: cicd

before_script:
  - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY

test:
  stage: test
  script:
    - docker pull golamrabbani3580/cicd:v1
    - docker run -e CI=true golamrabbani3580/cicd:v1 npm test


deploy:
  stage: deploy
  script:
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" > /tmp/deploy_key
    - chmod 600 /tmp/deploy_key
    - ssh-add /tmp/deploy_key
    - ssh -o StrictHostKeyChecking=no root@serverIP 'bash -s' < deploy.sh
  only:
    - master

Here is my deploy.sh file

docker pull golamrabbani3580/cicd:v1
docker build -t cicd:v1 .
docker run -d -p 3000:3000 cicd:v1

gitlab console stopping here for 1 hour and skipped.

$ docker run -e CI=true golamrabbani3580/cicd:v1 npm test
> [email protected] test
> mocha test.js
port: 4441
  GET /
    ✔ should return "Hello World"
  1 passing (22ms)

Upvotes: 0

Views: 67

Answers (1)

0074b60ae
0074b60ae

Reputation: 103

Current branch for the job was main or some other, but it was not master? The deploy job is set to only:master

Upvotes: 0

Related Questions