简体   繁体   English

在 Azure Devops Pipeline 中运行 Python 代码并将输出导出到 Devops Repos ($(Build.SourcesDirectory)) 中的文件夹

[英]Run Python Code within Azure Devops Pipeline and Export output to folder in Devops Repos ($(Build.SourcesDirectory))

How could I rewrite this python script so that it can run within azure devops pipeline and export the dataframe as a csv to the devops repository.我如何重写这个 python 脚本,以便它可以在 azure devops 管道中运行,并将数据帧作为 csv 导出到 devops 存储库。 I'm able to achieve this locally but would like to achieve this remotely.我能够在本地实现这一点,但想远程实现这一点。

Put different, how can I export a pandas dataframe to devops repos folder as a csv file using an azure devops pipeline task.换句话说,如何使用 azure devops 管道任务将 Pandas 数据帧作为 csv 文件导出到 devops repos 文件夹。 Below is the python script that needs to run as a pipeline task.下面是需要作为管道任务运行的 python 脚本。

local_path in this case should be azure devops path.在这种情况下 local_path 应该是 azure devops 路径。

from azureml.core import Workspace, Dataset
local_path = 'data/prepared.csv'
dataframe.to_csv(local_path)

⚠️You really should not do this. ⚠️你真的不应该这样做。 Azure pipelines are for building code, not for processing data. Azure 管道用于构建代码,而不是用于处理数据。 Assuming that you meant Azure DevOps Pipelines , opposed to Azure ML Pipelines .假设您指的是Azure DevOps Pipelines ,而不是Azure ML Pipelines

Also you should not commit data to your repository.此外,您不应将数据提交到您的存储库。

If you still want to proceed, here is an example for what you try to achieve.如果您仍想继续,这里是您尝试实现的目标的示例。 Note that for the last line, ie git push , you need to give the agent permission to write the repository.请注意,对于最后一行,即git push ,您需要授予代理写入存储库的权限。 See Run Git commands in a script for an approximate ☹️ documentation on how to do that on your account.有关如何在您的帐户上执行此操作的大致☹️ 文档,请参阅在脚本中运行 Git 命令

trigger: none

pool:
  vmImage: 'ubuntu-latest'

steps:
- checkout: self
  persistCredentials: true

- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.8'
    addToPath: true
    architecture: 'x64'

- script: |
    python your_data_generating_script.py
    git config --global user.email "you@example.com"
    git config --global user.name "Your Name"
    git add data/prepared.csv
    git commit -m'test commit'
    git push origin HEAD:master
  displayName: 'push data to master'

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

相关问题 Python Azure devOps Build Pipeline 中的突变测试报告 - Python Mutation testing reporting in Azure devOps Build Pipeline 如何在 Azure Devops 中使用构建变量运行 Python 任务 - How to run Python task with build variables in Azure Devops 在 Azure Devops 发布管道中启动 Python 看门狗 - Launching a Python watchdog in an Azure Devops Release pipeline 如何在 Azure Devops 的另一个构建管道中使用/pip 安装自定义 Python 包工件? - How to consume/pip install a custom Python package artifact in another build pipeline in Azure Devops? 如何构建、package 和部署 AWS SAM lambda function 从 azure Devops CI/CD 管道到 AWS - how to build, package and deploy AWS SAM lambda function of python from azure Devops CI/CD pipeline to AWS 运行 Azure DevOps 管道存在 ##[error]Bash exited with code '1' - Running Azure DevOps pipeline exists with ##[error]Bash exited with code '1' 在 Azure Devops 中运行管道期间下载任务附件 - Download Task attachment during a pipeline run in Azure Devops 将 Azure DevOps 管道详细信息发送到 SIEM - Send Azure DevOps Pipeline Details to SIEM 在 Azure DevOps 中自动创建文件夹? - Automate folder creation in Azure DevOps? 如何在 azure devops 管道上进行 python 覆盖测试时引发错误? - How can i raising error while python coverage test on azure devops pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM