[英]How to run external Python script within ADO pipeline that is not within the same repo
我已經用 python 編寫了一個掃描工具,可以在 PR 上為我們所有的回購協議運行,但我不確定最好的方法是將這段代碼的使用推廣到我們所有的個人管道。 任何指針將不勝感激!
我考慮過在管道中使用“Python 腳本”任務,但它似乎是為同一回購中的腳本量身定制的。
我考慮過使用 exe,但不確定這是否會在掃描工具本身的未來更改方面過於嚴格。
如果您想使用“Python 腳本”任務在同一組織內的另一個回購中運行 python 腳本文件,也許您可以嘗試將該任務添加為模板的一部分,然后在您當前的回購管道中運行該模板:
請查看以下步驟是否可以提供一些幫助:
1.例如,這里我在 repo 'store python file' 中有一個名為 'python2' 的最簡單的 python 文件
2.使用任務Python腳本創建一個模板,文件路徑指向'python2'
steps:
- checkout: template # the 'store python file' repo alias name in main azure-pipeline yaml
- task: PythonScript@0
inputs:
scriptSource: 'filePath'
scriptPath: '$(System.DefaultWorkingDirectory)/python2'
3.轉到當前倉庫和管道,添加 pr 觸發器並使用上面創建的模板:
pr:
branches:
include:
- main # modify as needed
paths:
include:
- README.md # modify as needed
variables:
acceptanceTestsRepoName: 'template' #the repo alias for 'store python file, you could change to whatever you want'
resources:
repositories:
- repository: template #the same with the above
name: {project name}/store python file #the real name of the repo
type: git
ref: main # modify as needed
stages:
- stage: A
displayName: AA
jobs:
- job: AAA
displayName: AAAA
pool:
vmImage: 'ubuntu-latest'
steps:
- template: 'template1@${{variables.acceptanceTestsRepoName}}'
然后在它被觸發並運行之后,你應該得到這樣的東西:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.