azure - 如何在没有浏览器身份验证的情况下在 Azure DevOps 构建管道中使用无服务器框架?

标签 azure azure-devops azure-functions azure-pipelines serverless-framework

我正在尝试使用我最初从桌面进行部署时创建的服务主体凭据,从 Azure DevOps 构建管道部署无服务器框架向我的 Azure 免费套餐帐户提供的简单 NodeJS hello-world 函数。我使用了多种构建代理和任务组合,包括 Windows 和 Ubuntu 代理以及 Bash、命令行、Azure Powershell 和 Azure CLI 任务,以及 DevOps 提供的服务主体凭据链接。我已确保将它们添加为管道变量,以便它们包含在任务的环境变量中,并且我已确认它们在任务运行时存在。我还确保已安装 Azure CLI 并使用订阅集登录。无论我调整什么设置/权限或尝试新配置,当任务成功运行到无服务器框架尝试部署的程度时,它总是尝试让我使用浏览器来验证我的帐户。这显然违背了 CI/CD 管道的目的,即使我确实使用浏览器进行身份验证,该过程也会卡在那里。

示例代码和部署在我的桌面上运行,因此我知道凭据有效。我相信我已经在构建管道中模拟了我在桌面上执行的每个步骤,但是当我的桌面在没有浏览器身份验证的情况下部署时,构建始终会请求它。有谁有这种方式的经验并知道我缺少什么步骤/配置?

要查看示例代码和流程,请查看 here或运行以下步骤:

  1. 无服务器创建 -t azure-nodejs -p testApp

  2. cd .\testApp\

  3. 更改 serverless.yml 中的节点运行时和区域(不支持 nodejs12.x,并且在美国西部没有免费套餐)

  4. 无服务器部署

这是我用来在桌面上运行此功能的链接:link

编辑:这是通过上述步骤创建的默认 serverless.yml:

service: azure-serverless-helloworld

provider:
  name: azure
  region: East US
  runtime: nodejs8.10

  environment:
    VARIABLE_FOO: 'foo'

plugins:
  - serverless-azure-functions

package:
  exclude:
    - local.settings.json
    - .vscode/**
    - index.html

functions:
  hello:
    handler: src/handlers/hello.sayHello
    events:
      - http: true
        x-azure-settings:
          methods:
            - GET
          authLevel: anonymous

  goodbye:
    handler: src/handlers/goodbye.sayGoodbye
    events:
      - http: true
        x-azure-settings:
          methods:
            - GET
          authLevel: anonymous

最佳答案

您可以尝试以下步骤在命令行任务中运行sls package来创建部署包,然后使用Azure Function App任务部署到 azure 。

1,install specific version nodejs using Node.js tool installer task

_

2, install serverless using npm task to run custom command

enter image description here

3, use npm task to run install command to install dependencies

_

4, Use command line task to run sls package to create the deployment package

enter image description here enter image description here

_

5, use azure function app deploy task to deploy the deployment package

enter image description here

关于azure - 如何在没有浏览器身份验证的情况下在 Azure DevOps 构建管道中使用无服务器框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59365944/

相关文章:

azure - 在 Windows Azure 中将 DS 与 D1_V2 VM 混合

Javascript - Azure 函数 blob 存储绑定(bind)与 sdk

c# - Visual Studio 调试器进入 Azure 函数项目的非用户代码

azure - 使用 Azure DevOps 跨环境部署 Azure 资源

azure-devops - 如何在 Azure DevOps 中按用户和日期报告记录的任务时间?

azure-devops - Azure 私有(private)生成代理 : No agent could be found with the following capabilities: npm, azureps

azure - 如何复制 Azure 资源组

azure - 有没有办法从 Azure 自动化帐户的混合工作组中删除过时的机器工作人员?

azure - Azure 通知中心的推送通知

azure - MS Azure 数据工厂 ADF 从 BLOB 到 Azure Postgres Gen5 8 核心的复制事件失败,连接因主机错误而关闭