Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,493
Community Members
 
Community Events
176
Community Groups

Bitbucket pipelines - Run or skip step based on Condition and Schedule

Scheduled Pipeline:
I'm looking for a solution in which we need to run the pipeline at a Scheduled time, like after every 8 hours.
image.png

Condition:
On the other hand, we need to skip the pipelines if there is no change in code, either by commit or by PR Merged.
But if the pipeline got kicked through Scheduled Time even if there is a Condition to skip pipelines without any change. Pipelines shouldn't skip it should run the CI process without skipping any steps

- step:

            name: 1X-Chrome

            condition:

              changesets:

                  includePaths:

                    # Any changes in Cypress Directories

                    - "fixture/**"                    

                    - "integration/**"

                    - "plugins/**"

                    - "support/**"

                    - "videos/**"

            <<: *step-chrome

            deployment: prod

With the above configuration as there is a condition to run only there is change in the mentioned paths. Because of that our Scheduled Jobs are also skips the pipeline step due to condition in it. 
Is there anyway we can add some sort of rules in which we will use both options like once the pipeline run with Schedule Job pipelines avoids the condition and runs the pipeline including all the step even with the condition steps. And when the pipeline run with the commit or PR Merged if there is no change in the conditon includePaths, pipeline skips the step  

1 answer

1 accepted

0 votes
Answer accepted

Hello @Abdul Rehman ,

Thank you for reaching out to Atlassian Community!

I'm afraid that is not possible to configure a rule to have the same pipeline skip/not skip a step based on is it was triggered by a schedule or a commit.

However to achieve the behavior you are looking for, I think you could create an additional custom triggered pipeline that you can use to configure your schedule, and it can contain the same steps as the pipeline you run for your commits/PRs, just excluding the condition includePaths.

Please find the example YML below : 

definitions: 
  steps:
    - step: &my-step-anchor
        name: Build and test
        script:
          - echo "this is my step's script"

pipelines:
  default: # This pipeline will automatically be triggered for any commit to a branch not elsewhere defined
    - step:
          <<: *my-step-anchor
          condition:
              changesets:
                 includePaths:
                   - "fixture/**"                    
                   - "integration/**"
                   - "plugins/**"
                   - "support/**"
                   - "videos/**"
  custom: 
   customPipelineForSchedule: # This custom pipeline is to be used in your schedule pipelines
      - step: *my-step-anchor

So in the above example, I created a YML anchor for the step, so you can reference it multiple times in your YML code without having to copy/paste the same code multiple times.
The 'default' pipelines will be triggered when there's any commit to any branch that is not elsewhere defined in your YML file. We are essentially getting the step defined in the anchor &my-step-anchor, and overriding the condition value of the step to check for the changes in the paths defined. If in the commit no file was modified in any of those paths, pipelines will skip this step.

As for the custom pipeline called customPipelineForSchedule, as the name says, it will be used to create your schedule pipeline. It is essentially the same step we have in the 'default' pipeline, but without the condition includePaths. So this is the pipeline you will choose when setting up your 8 hours schedule under the Pipelines page. Since this pipeline has no condition, it will run the step regardless of the path of the changed files.

Hope that helps to address your questions! Let me know in case you have any doubt.

Thank you, @Abdul Rehman .

Kind regards,

Patrik S

@Patrik S Thank you so much for your response, that's great we can create custom pipelines which we can use to schedule pipeline on main branch and that working fine. But I'm getting another issue even if there is a change in the directories which are mentioned in the condition section it still stops the pipeline and skips the pipeline. Can you please guide me on this as well why this condition is unable to detect the changes which I'm doing in the files in those directories 
This the pipeline which I have created on main branch




main
:

      - step:
          name: Preparing Dependencies
          caches:
            - npm
            - node
            - cypress
          script:
            - npx @bahmutov/print-env BITBUCKET
            - npm ci
      - parallel:
        - step:
            name: 1X-Chrome
            # Condition to stop pipeline if there are no changes in code
            condition:
                changesets:
                    includePaths:
                        # Any changes in Cypress Directories
                        - "fixtures/*.json"                    
                        - "integration/**/**/**/*.js"
                        - "plugins/*.js"
                        - "support/**/**/*.js"
                        # - "videos/**"
            <<: *step-chrome

 

            deployment: prod
         
        - step:
            name: 1X-Firefox
            # Condition to stop pipeline if there are no changes in code
            condition:
                changesets:
                    includePaths:
                        # Any changes in Cypress Directories
                        - "fixtures/*.json"                    
                        - "integration/**/**/**/*.js"
                        - "plugins/*.js"
                        - "support/**/**/*.js"
                        # - "videos/**"
            <<: *step-firefox
        - step:
            name: 1X-Edge
             # Condition to stop pipeline if there are no changes in code
            condition:
                changesets:
                    includePaths:
                        # Any changes in Cypress Directories
                        - "fixtures/*.json"                    
                        - "integration/**/**/**/*.js"
                        - "plugins/*.js"
                        - "support/**/**/*.js"
                        # - "videos/**"
            <<: *step-edge
Patrik S Atlassian Team Jun 22, 2022

Hey @Abdul Rehman ,

Could you please give us an example of the full path of a file in your repository that was changed and was supposed to run the step with the condition, but it skipped the pipeline instead? 

This way I can check if there's an issue/missconfiguration with your current conditions that have not considered that particular file.

Kind regards,

Patrik S

Like Abdul Rehman likes this

@Patrik S Thanks you for your respond here is my file-structure which I'm trying to apply condition on

Inside my repo named cypress_automation on bitbucket


cypress/fixtures/file.json

cypress/integration/folder-1/file.js

cypress/integration/folder-2/sub-folder2/file.js

cypress/plugin/file.js

cypress/support/folder1/sub-folder1/file.js

cypress/support/folder1/file.js

cypress/support/file.js

cypress/videos/folder1/file.mp4 nevermind about this folder I will remove this from the bitbucket-pipelines.yml file

I got my solution I was giving wrong path the correct path was above which I have mentioned already but I was not adding that to my file lolol

Before:

condition:

              changesets:

                  includePaths:

                    # Any changes in Cypress Directories

                    - "fixture/**"   ❌                  

                    - "integration/**" ❌

                    - "plugins/**" ❌

                    - "support/**" ❌

                    - "videos/**" ❌


After:

condition:

            changesets:

                includePaths:

                    # Any changes in Cypress Directories

                    - cypress/fixtures/** ✔️

                    - cypress/integration/** ✔️

                    - cypress/plugins/** ✔️

                    - cypress/support/** ✔️

Thanks @Patrik S  for helping

Like Patrik S likes this

Hey @Abdul Rehman ,

You're very welcome!

Happy to hear that it worked and thanks for sharing the solution!

Best regards,

Patrik S

Like Abdul Rehman likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events