繁体   English   中英

Azure DevOps 管道中的 AzureCLI 任务找不到脚本的位置

[英]AzureCLI task in Azure DevOps pipeline cannot find the location of scripts

我正在使用 Azure DevOps 管道,在我的一项任务中,我需要运行一个 bash 脚本,其中包含一些 Azure CLI 脚本。 我已将此脚本放在一个名为 scripts 的文件夹中,我的管道在管道文件夹中运行。 管道和脚本文件夹在根目录中处于同一级别。 下面显示了我运行 AzureCLI@2 任务的管道部分,但是当管道运行时它会引发找不到文件的错误!

项目文件夹结构

我已经将所有内容推送到存储库中,并且可以看到这些文件。 但是,管道找不到它。 我正在使用AzureCLI@2 文档链接为此任务提供值。 使用 AzureCLI 的管道部分如下:

pool: 
  vmImage: ubuntu-20.04

trigger:
  branches:
    include: 
      - "feature/ORGTHDATAMA-4810"
    exclude:
      - "main"
      - "release"
  paths:
    include:
      - "dip-comma-poc/**"

variables:
  - group: proj-comma-shared-vg

stages:
  - stage: DownloadArtifact
    displayName: "Download python whl from artifactory"
    jobs: 
    - job: DownloadArtifactJob
      steps:
      - checkout: self
      ## To download from devops artifactory with AZ CLI
      ## https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-cli-v2?view=azure-pipelines
      - task: AzureCLI@2
        inputs:
          azureSubscription: "sc-arm-pa042-man"
          scriptType: 'bash'
          scriptLocation: 'scriptPath'
          scriptPath: 'dip-comma-poc/deployment-pipelines/scripts/sp-login.sh'
          arguments: '$(SVCApplicationID) $(SVCSecretKey) $(SVCDirectoryID)'
        displayName: "Download python whl from artifactory"

这导致了以下错误:

没有这样的文件或目录错误

为了解决这个错误,我尝试使用 scriptPath 中的相对路径,如下所示,但它导致了同样的错误:

- task: AzureCLI@2
  inputs:
    azureSubscription: "sc-arm-pa042-man"
    scriptType: 'bash'
    scriptLocation: 'scriptPath'
    scriptPath: './scripts/sp-login.sh'
    arguments: '$(SVCApplicationID) $(SVCSecretKey) $(SVCDirectoryID)'
  displayName: "Download python whl from artifactory"

相对路径中没有这样的文件或目录

我也试过 inlineScript 但它还是找不到文件。

- task: AzureCLI@2
  inputs:
    azureSubscription: "sc-arm-pa042-man"
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    arguments: '$(SVCApplicationID) $(SVCSecretKey) $(SVCDirectoryID)'
    inlineScript: './scripts/sp-login.sh $1 $2 $3'
  displayName: "Download python whl from artifactory"

这也引发了同样的错误:

无此文件或目录

我如何在管道 yaml 文件中引用我的脚本,以便它不会引发如上所示的“没有这样的文件或目录错误”? 谢谢你。

在 Azure DevOps 的 web UI 上打开 Git 存储库,然后检查其文件结构是否如下图所示。

在此处输入图像描述

如果和这个文件结构一样。 您需要将 Azure CLI 任务上设置的文件路径更改为“ deployment-pipelines/scripts/sp-login.sh ”,而不是“ dip-comma-poc/deployment-pipelines/scripts/sp-login.sh ”。

      - task: AzureCLI@2
        inputs:
          azureSubscription: "sc-arm-pa042-man"
          scriptType: 'bash'
          scriptLocation: 'scriptPath'
          scriptPath: 'deployment-pipelines/scripts/sp-login.sh'
          arguments: '$(SVCApplicationID) $(SVCSecretKey) $(SVCDirectoryID)'
        displayName: "Download python whl from artifactory"

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM