Job dependencies branch filter (OD-197)
Chris opened 5 years ago

Hi,

I have my CI jobs defined, but I'm trying to simplify the jobs because there is a lot of code duplication. Right now I have the following

  • CI job for feature branches (build & test)
  • CI job for main branch (build & test & version bump)
  • CD job for main branch (dependency on CI on main branch, deploys staging/test system)
  • CI job for tags
  • CD job for tags (dependency on CI on tag, deploys prod/live system)

So all CI jobs do nearly the same and I'm wondering if it's possible to have something like this:

  • CI job (for all branches and tags)
  • Version bump job (dependency on CI job, but only if main branch)
  • CD job for staging (dependency on CI job, but only if main branch)
  • CD job for live (dependency on CI job, bit only if tag like version/**)

Right now I don't see any option to set dependencies on other jobs depending on specific branches. Do I miss something? Or do yo maybe think this would be a nice feature? Or do you maybe think a completely other solution would be more suitable?

Best regards, Chris

  • Robin Shen commented 5 years ago

    Just declare your downstream jobs (version bump, cd for staging/live etc.) to be dependent on CI job, and configure the job trigger of downstream jobs to fire on desired branches/tags.

  • Chris commented 5 years ago

    Unfortunately this does not work. I build my CI job (running on all branches) and a downstream job for staging deployment. The downstream job has the job dependency to CI job and a trigger for branch update on master. After the CI job ran on a feature branch (issue/26) the deployment job nevertheless started.

    46

  • Chris commented 5 years ago

    Shortened job definitions:

    version: 1
    jobs:
    - name: CI
      image: '@scripts:builtin:maven:determine-docker-image@'
      commands:
      - # does mvn build
      triggers:
      - !BranchUpdateTrigger
        paths: -pom.xml
      retrieveSource: true
      cloneCredential: !HttpCredential
        accessTokenSecret: retrieve-token
      artifacts: '**'
      cpuRequirement: 250m
      memoryRequirement: 128m
      retryCondition: never
      maxRetries: 3
      retryDelay: 30
      caches:
      - key: maven-cache
        path: /root/.m2/repository
      timeout: 3600
    - name: Deploy (Staging)
      image: docker
      commands:
      - # does docker build & deploy
      triggers:
      - !DependencyFinishedTrigger {}
      - !BranchUpdateTrigger
        branches: master
      retrieveSource: false
      cloneCredential: !DefaultCredential {}
      jobDependencies:
      - jobName: CI
        requireSuccessful: true
        artifacts: '**'
      cpuRequirement: 250m
      memoryRequirement: 128m
      retryCondition: never
      maxRetries: 3
      retryDelay: 30
      timeout: 3600
    
  • Robin Shen commented 5 years ago

    Remove the trigger "When dependency jobs finished". The "update branches master" trigger will tell Deployment job to trigger upon master update, and if it has any dependencies, it will wait for dependency to finish before firing itself.

  • Chris commented 5 years ago

    Thanks, works like a charm. Also needed to wrap my head around not defining the the branch update trigger everywhere even with correct dependencies, because then you'll end up in an andless loop. But everything works now. :)

  • Robin Shen changed state to 'Closed' 5 years ago
    Previous Value Current Value
    Open
    Closed
issue 1/1
Type
Question
Priority
Normal
Assignee
Issue Votes (0)
Watchers (3)
Reference
OD-197
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover