6
votes

I have a repository hosted on gitlab.com, it has several build jobs associated with it. I would like for an ability to deploy the compiled artifacts of any given build (generally in the form of HTML/CSS/JavaScript compiled files) to azure.

All of the guides/docs/tutorials I've seen so far (1, 2, 3, to name a few), focus on deploying files directly from a git repository, which I can see being useful in some cases, but isn't what I need in this case, as I want the compilation targets, and not the source.

Solutions welcome, we've been bashing our heads over this for several days now.

Alternatives to GitLab in which this is made possible (in case it's not in GitLab), will also be welcomed.

1

1 Answers

2
votes

Add a deployment stage that has the build dependencies, from a job or more then a job, and thus downloads the artifacts of those jobs see below .gitlab-ci.yml:

stages:
- build
- ...
- deploy

buildjob:1:
  stage: build
  script:
  - build_to_web_dir.sh
  artifacts:
    paths:
     - web

buildjob:2:
  stage: build
  script:
  - build_to_web_dir.sh
  artifacts:
    paths:
     - web

deploy:
  stage: deploy
  GIT_STRATEGY: none
  image:  microsoft/azure-cli
  dependencies:
   - buildjob:1
   - buildjob:2
  script:
  - export containerName=mynewcontainername
  - export storageAccount=mystorageaccount
  - az storage blob delete-batch --source ${containerName} --account-name ${storageAccount} --output table
  - az storage blob upload-batch --source ./web --destination ${containerName} --account-name ${storageAccount} --output table --no-progress

In the deploy job, only one directory will be in the CI_PROJECT_DIR ./web containing all files that the build jobs have produced.

checkout storage quickstart azure for creating and setting up the storage container, account details etc.

For the deploy stage we can use the microsoft/azure-cli docker image, so we can call from our script the az command, see storage-quickstart-blobs-cli for more detail explanation.

az storage blob upload-batch --source ./web --destination ${containerName} --account-name ${storageAccount} --output blobname --no-progress

will copy ./web to the storage container

we should not export for security reasons in the .gitlab-ci.yml:

export AZURE_STORAGE_ACCOUNT="mystorageaccountname"
export AZURE_STORAGE_ACCESS_KEY="myStorageAccountKey"

but they should be defined in the project_or_group/settings/ci_cd environment variables, so they'll be present in the script environment.