gpt4 book ai didi

azure - 如何在Azure管道中获取github存储库名称

转载 作者:行者123 更新时间:2023-12-02 05:54:53 25 4
gpt4 key购买 nike

Azure 中是否有任何变量可以用来获取源文件夹的名称(存储库名称)。我尝试使用 Build.SourcesDirectorySystem.DefaultWorkingDirectory ,两者都返回 /Users/runner/work/1/s 。我希望得到 MyProjectFolderName 这是我的项目在 github 中的源目录。

最佳答案

如果您 checkout self repo(这是默认情况),那么只需按照 Daniel 的建议即可:

$(Build.Repository.Name)

yml 文件如下:

trigger:
- none

pool:
vmImage: ubuntu-latest

steps:
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
str = "$(Build.Repository.Name)"

str.split("/")

#get the last name
print(str.split("/")[-1])

enter image description here

如果您只 checkout 一个存储库而不 checkout 自己,则只需使用下面的 yml:

trigger:
- none

pool:
vmImage: ubuntu-latest
resources:
repositories:
- repository: 222
type: github
name: xxx/222
endpoint: xxx
- repository: 333
type: github
name: xxx/333
endpoint: xxx
variables:
- name: checkoutreporef
value: $[ resources.repositories['333'].name ]
steps:
- checkout: 333
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
str = "$(checkoutreporef)"

str.split("/")

#get the last name
print(str.split("/")[-1])

enter image description here

如果您 checkout 两个或更多存储库,下面的 yml 将帮助您获取存储库名称:

trigger:
- none

pool:
vmImage: ubuntu-latest
resources:
repositories:
- repository: 222
type: github
name: xxx/xxx
endpoint: xxx
- repository: 333
type: github
name: xxx/xxx
endpoint: xxx
steps:
- checkout: 222
- checkout: 333
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
import os

#get current sub folders name
def getfoldersname():
folders = [f for f in os.listdir('.') if os.path.isdir(f)]
return folders
#print each folder name
def printfoldersname():
for folder in getfoldersname():
print(folder)

printfoldersname()

enter image description here

关于azure - 如何在Azure管道中获取github存储库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73572283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com