#572  Trigger on branch update/creation not working
Closed
rhdev opened 2 years ago

I have a Build on ProjectOne which clones another repo from GitLab into a new Branch based on the latest tag of the remote GitLab repo. I have a Build on ProjectTwo which has triggers based on branches being created on ProjectOne, but it doesn't trigger.

ProjectOne

version: 15
jobs:
- name: update branch
  steps:
  - !CommandStep
    name: clone from gitlab and push to branch
    runInContainer: false
    interpreter: !DefaultInterpreter
      commands:
      - git clone https://gitlab.com/Remmina/Remmina.git remmina-gitlab
      - cd remmina-gitlab
      - git remote add upstream http://user:password@@server:6610/remmina-gitlab
      - LATESTTAG=$(git describe --tags)
      - git checkout -b $LATESTTAG
      - git push -f upstream $LATESTTAG
    useTTY: false
    condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
  retryCondition: never
  maxRetries: 3
  retryDelay: 30
  cpuRequirement: 500
  memoryRequirement: 256
  timeout: 3600
- name: when new branch
  steps:
  - !CommandStep
    name: just echo on trigger
    runInContainer: false
    interpreter: !DefaultInterpreter
      commands:
      - echo "this was triggered"
    useTTY: false
    condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
  triggers:
  - !BranchUpdateTrigger
    branches: -main
    projects: remmina-gitlab
  retryCondition: never
  maxRetries: 3
  retryDelay: 30
  cpuRequirement: 500
  memoryRequirement: 256
  timeout: 3600

ProjectTwo

version: 15
jobs:
- name: do nothing
  jobExecutor: bashExec
  steps:
  - !CommandStep
    name: just echo
    runInContainer: false
    interpreter: !DefaultInterpreter
      commands:
      - echo "triggered by new branch"
    useTTY: false
    condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
  triggers:
  - !BranchUpdateTrigger
    projects: remmina-gitlab
  retryCondition: never
  maxRetries: 3
  retryDelay: 30
  cpuRequirement: 500
  memoryRequirement: 256
  timeout: 3600
Robin Shen commented 2 years ago

This is by design. A job can only be triggered by commits in same repository. The applicable projects setting here does not mean to monitor branches of other projects. It instead adds another constraint for project path in order for the triggered to work.

This setting is useful for instance when some trigger should be turned off in forked projects. I will add more explanation to this setting to avoid confusion.

For your case, you may consider to trigger ProjectTwo from ProjectOne's job command via OneDev's restful api:

https://code.onedev.io/help/api/io.onedev.server.rest.JobRunResource/runBuild

Robin Shen commented 2 years ago

Just curious, why ProjectTwo needs to monitor branch updates of ProjectOne?

rhdev commented 2 years ago

Hmm, thanks for that. I was trying to do it this way because it wouldn't work monitoring its own repository for new branches. I had the build yml in main branch with two build jobs, the first would pull from the remote repo and create a branch, the second should trigger on a new branch but it wouldn't work.

I'll take another look.

Robin Shen changed fields 2 years ago
Name Previous Value Current Value
Type
Bug
Support Request
Robin Shen commented 2 years ago

You will need to put the job "when new branch" in project https://gitlab.com/Remmina/Remmina.git. The branch trigger works as below:

Whenever a commit is pushed to a branch at OneDev side, OneDev will examine pushed commit to see if it contains onedev build spec, if yes, it continues to examine each job to see if the trigger condition is matched, if matched, the job will be fired.

Robin Shen changed state to 'Closed' 2 years ago
Previous Value Current Value
Open
Closed
issue 1 of 1
Type
Question
Priority
Normal
Assignee
Issue Votes (0)
Watchers (4)
Reference
onedev/server#572
Please wait...
Page is in error, reload to recover