Fan-out fan-in with build-router-start

Hey, I’m trying to build fan-out fan-in scheme with this guide: https://blog.bitrise.io/start-multiple-builds-with-the-same-trigger and I am also using bitrise.yml from code approach as described here: https://devcenter.bitrise.io/tips-and-tricks/use-bitrise-yml-from-repository/

This is a snippet from my config file:

format_version: "7"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: other
trigger_map:
- push_branch: '*'
  workflow: primary
- pull_request_source_branch: '*'
  workflow: primary
workflows:
  primary:
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.14: {}
    - script@1.1.5:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/bin/bash
            echo "Trigger $SOURCE_BITRISE_BUILD_NUMBER"
    - build-router-start@0.11.2:
        inputs:
        - access_token: $BITRISE_ACCESS_TOKEN
        - workflows: |-
            ios
            android
  ios:
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.14: {}
    - script@1.1.5:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/bin/bash
            echo "Build ios $SOURCE_BITRISE_BUILD_NUMBER"
  android:
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.14: {}
    - script@1.1.5:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/bin/bash
            echo "Build android $SOURCE_BITRISE_BUILD_NUMBER"

However it fails with the following error:

+------------------------------------------------------------------------------+
| (3) build-router-start@0.11.2                                                |
+------------------------------------------------------------------------------+
| id: build-router-start                                                       |
| version: 0.11.2                                                              |
| collection: https://github.com/bitrise-io/bitrise-steplib.git                |
| toolkit: go                                                                  |
| time: 2019-04-19T13:55:04Z                                                   |
+------------------------------------------------------------------------------+
|                                                                              |
Config:
- AppSlug: [REDACTED]
- BuildSlug: ***********
- BuildNumber: 6
- AccessToken: *****
- WaitForBuilds: false
- Workflows: ios
android
- Environments: 
Starting builds:
Failed to start build, error: failed to get response, statuscode: 400, body: {"status":"error","message":"workflow (ios) did not match any workflows defined in app config","slug":"[REDACTED]","service":"bitrise"}
|                                                                              |
+---+---------------------------------------------------------------+----------+
| x | build-router-start@0.11.2 (exit code: 1)                      | 4.13 sec |
+---+---------------------------------------------------------------+----------+
| Issue tracker: ...com/bitrise-steplib/bitrise-step-build-router-start/issues |
| Source: https://github.com/bitrise-steplib/bitrise-step-build-router-start   |
+---+---------------------------------------------------------------+----------+

Is this even possible to use this approach when my configs are hosted in git? It appears to fail to trigger a workflow which is only available through git.

Any workarounds to implement it?

Hi @max,

Currently in this implementation the build-router-start step would expect the ios and android workflows to be present in the bitrise.yml that is stored online as well. When starting a build with this step it triggers a build on our website and the previously mentioned workflows are only available in the bitrise.yml stored in your repo.

What can be a possible solution for your case would be to create workflows with the same name on our website as well and these workflows would contain the steps needed for cloning the repo and a Bitrise Run step to start the workflow with the same name from the specified bitrise.yml in your repo. So basically a workflow that is stored in our yml on our website would look something like this:

        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.14: {}
    - bitrise-run@0.9.1: {}

Let me know if you’d have any questions or issues! :nerd_face:

1 Like

thanks @tamasbazsonyi, however this is kind of a solution I wanted to avoid since I would really prefer to keep config in the repo as a single source of truth :frowning:

as an alternative I’m considering sending workflow id as an env variable, do you think this might work?

@max That would be perfectly doable as well, but the implementation would be pretty similar :nerd_face:in that case I’d say you’d need a default runner workflow. So basically what you would be doing is triggering a common build which would get the workflow to build as an env var. In this case you’d also need different build-router-start steps if you want to trigger multiple workflows and these steps would look something like this:

        inputs:
        - workflows: runner_workflow
        - environment_key_list: WORKFLOW_TO_RUN
        - access_token: "$BITRISE_ACCESS_TOKEN"

The WORKFLOW_TO_RUN env var would indicate which workflow should be ran from the yml in the repository and the runner_workflow. Let me know if you’d have any issues or questions :nerd_face:Also if you’d need a sample for these workflows let me know and I’ll be more than happy to put together a sample for you :nerd_face:

So far I ended up with the following:

  • bitrise.yml in web - accepts call and dispatches to actual workflow in repo:
---
format_version: '7'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: other
workflows:
  ci:
    after_run:
    - run_from_repo
  run_from_repo:
    steps:
    - activate-ssh-key:
        run_if: ''
    - git-clone: {}
    - script:
        title: continue from repo
        inputs:
        - content: |-
            #!/bin/bash
            set -ex
            echo "workflow to run from trigger: ${WORKFLOW_TO_RUN:-primary}"
            bitrise run "${WORKFLOW_TO_RUN:-primary}"
  ios:
    after_run:
    - run_from_repo
    steps:
    - script@1.1.5:
        inputs:
        - content: |
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            envman add --key WORKFLOW_TO_RUN --value ios
  android:
    after_run:
    - run_from_repo
    steps:
    - script@1.1.5:
        inputs:
        - content: |
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            envman add --key WORKFLOW_TO_RUN --value android
trigger_map:
- push_branch: task/ci-2.0
  workflow: ci

  • bitrise.yml in repo - does actual job of building an app:
format_version: "7"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: other
trigger_map:
- push_branch: '*'
  workflow: primary
- pull_request_source_branch: '*'
  workflow: primary
workflows:
  primary:
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.14: {}
    - script@1.1.5:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/bin/bash
            echo "Trigger $SOURCE_BITRISE_BUILD_NUMBER"
    - build-router-start@0.11.2:
        inputs:
        - access_token: $BITRISE_ACCESS_TOKEN
        - workflows: |-
            ios
            android
    - script@1.1.5:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/bin/bash
            echo "slugs?  $ROUTER_STARTED_BUILD_SLUGS"
    - build-router-wait@0.9.1:
        inputs:
        - access_token: $BITRISE_ACCESS_TOKEN
        - buildslugs: $ROUTER_STARTED_BUILD_SLUGS

  ios:
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.14: {}
    - script@1.1.5:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/bin/bash
            # build ios

  android:
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.14: {}
    - script@1.1.5:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/bin/bash
            # build android

I wish this kind of a set up was a bit more straightforward…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.