ci/cd 管道的 yaml 配置

问题描述 投票:0回答:1

我有一个 playwrite/python 自动化框架,我正在尝试配置 yaml 文件。然而我没有运气。我的目标是有一个阶段来安装所有依赖项,然后使用该阶段作为我将创建的任何阶段的依赖项。

这是我当前的代码。它没有任何错误,但看起来并没有安装指定的依赖项并在阶段上运行测试。

trigger:
  branches:
    include:
      - main  # Adjust the branch name as needed

pool:
  vmImage: 'windows-latest'  # Same VM image for all stages

stages:
  - stage: InstallDependencies
    displayName: "Install Dependencies"
    jobs:
      - job: Install
        displayName: "Install Dependencies"
        steps:
          # Use the same Python version
          - task: UsePythonVersion@0
            inputs:
              versionSpec: '3.x'  # Adjust according to your Python version requirements
              addToPath: true

          # Set up the virtual environment and install dependencies
          - script: |
              python -m venv .venv
              .venv\Scripts\activate
              python.exe -m pip install --upgrade pip
              python.exe -m pip install behave
              python.exe -m pip install -r requirements.txt
              python -m playwright install
            displayName: "Set up Python Virtual Environment and Install Dependencies"

          # Publish the virtual environment as an artifact
          - task: PublishBuildArtifacts@1
            inputs:
              PathtoPublish: '.venv'  # Path to the virtual environment
              ArtifactName: 'venv'   # Artifact name
              publishLocation: 'Container'

  # Run Inventory Feature Tests
  - stage: InventoryFeature
    dependsOn: InstallDependencies
    displayName: "Run Inventory Feature Tests"
    jobs:
      - job: RunInventory
        displayName: "Run Inventory Feature Tests"
        steps:
          # Use the same Python version
          - task: UsePythonVersion@0
            inputs:
              versionSpec: '3.x'
              addToPath: true

          # Download the virtual environment artifact
          - task: DownloadBuildArtifacts@0
            inputs:
              artifactName: 'venv'
              downloadPath: '$(System.DefaultWorkingDirectory)'

          # Activate the virtual environment and run tests
          - script: |
              $(System.DefaultWorkingDirectory)\venv\Scripts\activate
              behave features/inventory.feature --junit --junit-directory reports/inventory
            displayName: "Run Inventory Feature Tests"

          # Publish test results
          - task: PublishTestResults@2
            inputs:
              testResultsFiles: 'reports/inventory/*.xml'
              testRunTitle: "Inventory Feature Tests"

  # Run Stores Feature Tests
  - stage: StoresFeature
    dependsOn: InstallDependencies
    displayName: "Run Stores Feature Tests"
    jobs:
      - job: RunStores
        displayName: "Run Stores Feature Tests"
        steps:
          # Use the same Python version
          - task: UsePythonVersion@0
            inputs:
              versionSpec: '3.x'
              addToPath: true

          # Download the virtual environment artifact
          - task: DownloadBuildArtifacts@0
            inputs:
              artifactName: 'venv'
              downloadPath: '$(System.DefaultWorkingDirectory)'

          # Activate the virtual environment and run tests
          - script: |
              $(System.DefaultWorkingDirectory)\venv\Scripts\activate
              behave features/stores.feature --junit --junit-directory reports/stores
            displayName: "Run Stores Feature Tests"

          # Publish test results
          - task: PublishTestResults@2
            inputs:
              testResultsFiles: 'reports/stores/*.xml'
              testRunTitle: "Stores Feature Tests"

  # Run Colors Feature Tests
  - stage: ColorsFeature
    dependsOn: InstallDependencies
    displayName: "Run Colors Feature Tests"
    jobs:
      - job: RunColors
        displayName: "Run Colors Feature Tests"
        steps:
          # Use the same Python version
          - task: UsePythonVersion@0
            inputs:
              versionSpec: '3.x'
              addToPath: true

          # Download the virtual environment artifact
          - task: DownloadBuildArtifacts@0
            inputs:
              artifactName: 'venv'
              downloadPath: '$(System.DefaultWorkingDirectory)'

          # Activate the virtual environment and run tests
          - script: |
              $(System.DefaultWorkingDirectory)\venv\Scripts\activate
              behave features/colors.feature --junit --junit-directory reports/colors
            displayName: "Run Colors Feature Tests"

          # Publish test results
          - task: PublishTestResults@2
            inputs:
              testResultsFiles: 'reports/colors/*.xml'
              testRunTitle: "Colors Feature Tests"

或者是否有人有更好的建议来实现相同的目标?感谢任何指导。

python python-3.x azure-devops azure-pipelines playwright
1个回答
0
投票

Microsoft 托管的代理在各个虚拟机中运行,这些虚拟机每次运行后都会重新映像

这意味着代理中未包含的工具和软件必须安装在需要这些工具和软件的每个作业上。

© www.soinside.com 2019 - 2024. All rights reserved.