简体   繁体   English

如何将构建工件从GitLab CI部署到Azure应用服务?

[英]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. 所有导游/文档/教程到目前为止,我已经看到了( 123 ,仅举几例),专注于直接从一个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.

相关问题 通过 gitlab ci 部署 vue 到 azure static Z2567A5EC9705061AC2CZ98403 - Deploy vue via gitlab ci to azure static web app (service) Gitlab CI/CD 部署到 Azure Web 服务 - Gitlab CI/CD deploy to Azure Web Service 将 GitLab Web 应用程序部署到 Azure 应用程序服务 - Deploy GitLab web app to Azure app service 如何从 GitLab 容器注册表将 Docker 容器部署到 Azure 应用服务 - How to deploy a Docker container to Azure App Service from GitLab container registry 如何将 React 应用程序的生产 npm 构建部署到 Azure 应用服务 - How can I deploy production npm build of react app to Azure App Service 如何从VSTS部署到Azure应用服务? - How to deploy to azure app service from VSTS? 如何从github部署到Azure应用服务 - How to Deploy from github to Azure App Service 如何构建 netcore 3.0 Webapi 并部署到 Azure Linux 应用服务 - How to build a netcore 3.0 Webapi and deploy to an Azure Linux app service azure devops 构建和部署到应用服务 - azure devops build and deploy to app service 我们如何配置以从基于 yaml 的 azure CI 管道的 Jfrog 工件中提取 npm 包? - how can we configure to pull npm packages from Jfrog artifacts for yaml based azure CI Pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM