Search code examples
gitgitlabgitlab-cigitlab-ci-runner

How to pull branch at specific tag in Gitlab Pipeline


Is there a way to make the deploy-prod job in my GitLab pipeline pull the main branch at a particular version tag instead of always pulling the latest code? Here $VERSION_NUMBER is a variable available in the pipeline

deploy-prod:
  tags:
    - prod-runner
  image: docker.xxx/nodejs:14
  stage: deploy-prod
  environment: 
    name: prod
  script:
    - npm install        
    - npx sequelize-cli db:migrate
  when: manual
  rules:
    - if: $VERSION_NUMBER != ''

Solution

  • You can run before_script to fetch all tags and in script do a checkout to specific tag by passing VERSION_NUMBER.

    before_script:
      - git fetch --tags
    
    script:
      - git checkout tags/${VERSION_NUMBER}
      # Your commands here...