2021年2月6日星期六

Question about Azure Devops pipeline question about task conditions

I've been trying to setup an Azure Devops pipeline for testing purposes and i'm struggling to understand why one of my tasks runs the script line despite being skipped.

Here's the pipeline yaml code:

## Example azure-pipelines.yml    ## Event (branch to trigger the pipeline execution)  trigger:    branches:      include:      - main      exclude:      - My-branch # Will not run    # Configures pipeline execution on pull requests  pr:    branches:      include:      - main      exclude:      - My-branch # Will not run        # Environment variables created  variables:  - group: my-keys    ## OS where the pipeline will run  pool:    vmImage: 'ubuntu-latest'    # List of stages for your application  stages:  - stage: Test    displayName: Application Testing    # List of jobs the pipeline stage will run    jobs:    - job: MyJob      displayName: Install packages and and publishes      variables:        # Sets the environment variable to cache the application packages        npm_config_cache: $(Pipeline.Workspace)/.npm       # List of steps for the job      steps:      - task: NodeTool@0        inputs:          versionSpec: '12.x'        displayName: 'Install Node.js'        - task: Cache@2        displayName: Install and cache packages        inputs:          key: 'npm | "$(Agent.OS)" | package-lock.json'          restoreKeys: |            npm | "$(Agent.OS)"          path: $(npm_config_cache)      - script: npm ci        condition: ne(variables.CACHE_RESTORED, 'true')      - task: Npm@1        displayName: Publish and auto accept        condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/main'))      - script: npx my-package  --with-token=${my-keys} --auto-publish-changes      - task: Npm@1        displayName: Publish        condition: eq(variables['Build.Reason'], 'PullRequest')      - script: npx my-package --with-token=${my-keys}      - script: echo $ $  

A example, for instance when a push is made into the main branch it runs Publish and auto accept followed by the Publish, when it technically should only run the first one. One other thing that i saw was that when a pull request is incoming to one other branch rather than main it shouldn't trigger the script associated to Publish and auto accept but instead jump over that and run only the script in Publish, but instead it runs the scripts in both.

If anyone could provide some help with this i would appreciate it.

Thanks in advance

https://stackoverflow.com/questions/66068403/question-about-azure-devops-pipeline-question-about-task-conditions February 06, 2021 at 02:08AM

没有评论:

发表评论