Deploy On Gitlab with Staging from dev and Production from Master branch


#1

Hi Hugo member,
I need help and thanks in advance for help.
Requirement:
I have made two branch

  1. Dev for staging. [config-development.toml]
  2. Master for Production [config-production.toml]

Problem after deploy
when I deploy with .gitlab-ci.yml Production is working fine but development menu URL showing production URL this is the main issue.

Below is the .gitlab-ci.yml code

variables:
  PROD_HUGO_ENV: "production"
  PROD_BASE_URL: "https://prodwww.abc.com/"
  PROD_DOMAIN: "prodwww.abc.com"

  STAGING_HUGO_ENV: "development"
  STAGING_BASE_URL: "https://wwwdev.abc.com/"
  STAGING_DOMAIN: "wwwdev.abc.com"
  
.production_variables: &production_variables
  HUGO_ENV: ${PROD_HUGO_ENV}
  BASE_URL: ${PROD_BASE_URL}
  DOMAIN: ${PROD_DOMAIN}

.staging_variables: &staging_variables
  HUGO_ENV: ${STAGING_HUGO_ENV}
  BASE_URL: ${STAGING_BASE_URL}
  DOMAIN: ${STAGING_DOMAIN}
stages:
  - build
  - deploy

# ====

.build_base: &build_base
  stage: build
  # All available Hugo versions are listed here: https://gitlab.com/pages/hugo/container_registry
  # image: registry.gitlab.com/pages/hugo:0.38.2
  image: monachus/hugo
  artifacts:
    paths:
      - public
  script:
  - export
  - hugo --baseURL ${BASE_URL}

build:production:
  <<: *build_base
  variables:
    <<: *production_variables
    GIT_SUBMODULE_STRATEGY: recursive
  only:
   - master
   
   
build:staging:
  <<: *build_base
  variables:
    <<: *staging_variables
    GIT_SUBMODULE_STRATEGY: recursive
  only:
   - dev

.deploy_base: &deploy_base
  stage: deploy
  image: monachus/hugo
  script:
    - hugo --baseURL ${BASE_URL}



deploy:production:
  <<: *deploy_base
  variables:
    <<: *production_variables
  dependencies:
   - build:production
  only:
   - master

deploy:staging:
  <<: *deploy_base
  variables:
    <<: *staging_variables
  dependencies:
   - build:staging
  only:
   - dev

and for menu code

{{ range .Site.Menus.main }}
								{{ if .HasChildren }}
									<li class="menu-item-has-children">
										<a href="{{if or ((ne .URL "#") (ne .URL " ")) }} {{ $baseUrl }}{{ .URL  }} {{else}} javascript:void(0) {{end}}"> {{ .Name }}</a>
										<ul class="sub-menu">
											{{ range .Children }}
												<li><a href="{{ $baseUrl }}{{ .URL }}">{{ .Name }}</a></li>
											{{ end }}
										</ul>
									</li>
									{{ else }}
									<li><a href="{{ $baseUrl }}{{ .URL  }}"> {{ .Name }}</a> </li>
								{{ end }}
							{{end}}
							{{ if .Site.Params.freeTrial.enable }}
								<li><a class="btn-free" href="{{ .Site.Params.freeTrial.buttonUrl }}"> {{ .Site.Params.freeTrial.buttonText }} </a> </li>
							{{ end }}

and config.toml

baseurl = "https://wwwdev.abc.com"
contentdir    = "content"
layoutdir     = "layouts"
publishdir    = "public"

env = "development"

languageCode = " "

	
[[menu.main]]
    name = "Home"
    url = "/"
    weight = 1
    identifier = "home"

[[menu.main]]
    name = "About us"
    url = "/aboutus/"
    weight = 2
    identifier = "about"
	
[[menu.main]]
    name = "About T Solutions"
    url = "/aboutus/"
    weight = 22
    parent = "about"

	
[[menu.main]]
    name = "Contact us "
    url = "/contact/"
    weight = 5
    identifier = "contact"

Please help


#2

Welcome to the forums. Please put your code samples together in a working repo that we can clone. Currently your menu loads javascript and we don’t know what your content files look like. We need to see what is happening. :slight_smile:


#3

I am not familiar with all those GitLab options. In my setup, I put it all in the Hugo command:

script:
- hugo -e "development" --config config.toml,config-dev.toml

The second config file (config-dev.toml) overwrite some variables in config.toml, such as baseurl.


#4

In the menu, it looks like you are using a custom defined variable ($baseurl) instead of the system’s (config) baseurl.

The problem might lie there - though I can’t tell. Check to see if your variable is setting the production baseurl. If it is, you might like to try changing to use hugo’s url management.