[英]How can one deploy build artifacts from GitLab CI to an Azure app service?
I have a repository hosted on gitlab.com, it has several build jobs associated with it. 我有一个托管在gitlab.com上的存储库,它有几个与之关联的构建作业。 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. 我希望能够将任何给定构建的编译工件(通常以HTML / CSS / JavaScript编译文件的形式)部署到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. 所有导游/文档/教程到目前为止,我已经看到了( 1 , 2 , 3 ,仅举几例),专注于直接从一个Git仓库,我可以看到在某些情况下是有用的部署文件,但是,这不是”在这种情况下我需要什么,因为我想要编译目标,而不是源代码。
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. GitLab的替代方案(如果它不在GitLab中)也将受到欢迎。
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: 从作业或更多作业添加具有构建依赖关系的部署阶段,从而下载这些作业的工件,如下所示.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. 在部署作业中,只有一个目录位于CI_PROJECT_DIR ./web
其中包含构建作业生成的所有文件。
checkout storage quickstart azure for creating and setting up the storage container, account details etc. checkout storage quickstart azure用于创建和设置存储容器,帐户详细信息等。
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. 对于部署阶段,我们可以使用microsoft/azure-cli
docker镜像,因此我们可以从脚本中调用az
命令,有关详细说明,请参阅storage-quickstart-blobs-cli 。
az storage blob upload-batch --source ./web --destination ${containerName} --account-name ${storageAccount} --output blobname --no-progress
will copy ./web to the storage container 将./web复制到存储容器中
we should not export for security reasons in the .gitlab-ci.yml
: 出于安全原因,我们不应在.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. 但是它们应该在project_or_group / settings / ci_cd环境变量中定义,因此它们将出现在脚本环境中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.