简体   繁体   English

使用来自 Azure 管道的服务连接对 Python 脚本任务进行身份验证

[英]Authenticate Python script task using service connection from Azure pipeline

I need to execute a Python script as part of my CICD process that will do some executions on existing files in a data lake gen 2/blob storage.我需要执行 Python 脚本作为我的 CICD 进程的一部分,该脚本将对数据湖第 2 代/blob 存储中的现有文件执行一些执行。

I don't know how to authenticate the script so that it can perform the actions needed.我不知道如何对脚本进行身份验证,以便它可以执行所需的操作。

Python script task Python 脚本任务

 task: PythonScript@0
  inputs:
    scriptSource: 'filePath'
    scriptPath: ./script.py
    #arguments: # Optional
    #pythonInterpreter: # Optional
    #workingDirectory: # Optional
    #failOnStderr: false # Optional

An Azure Powershell task has an input option to put in a azureSubscription. Azure Powershell 任务具有用于放入 azureSubscription 的输入选项。 Maybe I can pass in an argument?也许我可以传递一个论点?

Based on your requirement, you need to use the Authentication information in the Service Connection.根据您的要求,您需要使用服务连接中的身份验证信息。

To meet your requirement, you can choose to use Azure CLI task and enable the option: addSpnToEnvironment: true .为了满足您的要求,您可以选择使用 Azure CLI 任务并启用选项: addSpnToEnvironment: true

Refer to this doc: Azure CLI task请参阅此文档: Azure CLI 任务

Adds service principal ID and key of the Azure endpoint you chose to the script's execution environment.将您选择的 Azure 端点的服务主体 ID 和密钥添加到脚本的执行环境。

Here is an example:这是一个例子:

steps:
- task: AzureCLI@2
  displayName: 'Azure CLI '
  inputs:
    azureSubscription: xx
    scriptType: bash
    scriptLocation: inlineScript
    inlineScript: |
     echo "##vso[task.setvariable variable=ARM_CLIENT_ID]$servicePrincipalId" 
     
     echo "##vso[task.setvariable variable=ARM_CLIENT_SECRET]$servicePrincipalKey"
    
     echo "##vso[task.setvariable variable=ARM_TENANT_ID]$tenantId"
    addSpnToEnvironment: true

In this case, you can set the Authentication information as pipeline variable.在这种情况下,您可以将身份验证信息设置为管道变量。 Then you can use the pipeline variable in next tasks.然后您可以在下一个任务中使用管道变量。

$(ARM_CLIENT_ID)

$(ARM_CLIENT_SECRET)

$(ARM_TENANT_ID)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Python 脚本以用户身份向 Azure 应用服务进行身份验证? - How can I authenticate as a user to Azure App Service from Python script? 使用 Python 脚本的 ADF 管道中的 Azure 函数 - Azure function in ADF pipeline using a Python script 在 Azure 中存储服务主体凭据以使用 Python 对 Key Vault 进行身份验证 - Storing Service Principal Credentials in Azure to Authenticate Key Vault using Python 如何使用服务主体和 Python SDK 对 Azure 进行身份验证? - How do I authenticate to Azure using a Service Principal and the Python SDK? 认证 Azure Email Python 中使用服务主体的通信服务 - Authenticate Azure Email Communication Services using Service Principals in Python 如何在 Azure DevOps 管道中验证 PythonScript 任务 - How to authenticate PythonScript task within Azure DevOps Pipeline 如何从 azure 管道获取存储在 python 脚本中的变量的值 - how to get the value of a variable stored in a python script from azure pipeline 使用 python 从 azure function 触发 Azure Devops 管道 - Trigger an Azure Devops pipeline from an azure function using python 如何使用 Python 脚本退出代码作为 Azure 管道中以下任务的条件? - How to use a Python script exit code as a condition for the following task in Azure Pipeline? pip 在 azure 管道中安装 azure-functions 失败,执行 pip 身份验证任务 - pip install azure-functions in azure pipeline fails with pip authenticate task
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM