########################
# Job configuration for fuel
########################
- project:
    name: fuel-project-jobs

    project: 'fuel'

    installer: 'fuel'

    stream:
        - master:
            branch: '{stream}'
            gs-pathname: ''
            disabled: false
        - colorado:
            branch: 'stable/{stream}'
            gs-pathname: '/{stream}'
            disabled: false

    jobs:
        - 'fuel-build-daily-{stream}'
        - 'fuel-merge-build-{stream}'
        - 'fuel-merge-deploy-virtual-{stream}'
        - 'fuel-deploy-generic-daily-{stream}'

########################
# job templates
########################
- job-template:
    name: 'fuel-build-daily-{stream}'

    disabled: '{obj:disabled}'

    concurrent: false

    properties:
        - throttle:
            enabled: true
            max-total: 1
            max-per-node: 1
            option: 'project'

    parameters:
        - project-parameter:
            project: '{project}'
        - gerrit-parameter:
            branch: '{branch}'
        - 'opnfv-build-ubuntu-defaults'
        - '{installer}-defaults'
        - choice:
            name: FORCE_BUILD
            choices:
              - 'false'
              - 'true'
            description: "Force build even if there is no changes in fuel repo. Default false"
        - fuel-project-parameter:
            gs-pathname: '{gs-pathname}'

    scm:
        - git-scm

    triggers:
        - timed: '0 H/4 * * *'

    wrappers:
        - timeout:
            timeout: 360
            fail: true

    builders:
        - shell:
            !include-raw-escape: ./fuel-build.sh
        - shell:
            !include-raw-escape: ./fuel-upload-artifact.sh
        - shell:
            !include-raw-escape: ./fuel-workspace-cleanup.sh

    publishers:
        - email:
            recipients: jonas.bjurel@ericsson.com stefan.k.berg@ericsson.com fzhadaev@mirantis.com

- job-template:
    name: 'fuel-merge-build-{stream}'

    disabled: '{obj:disabled}'

    concurrent: true

    parameters:
        - project-parameter:
            project: '{project}'
        - gerrit-parameter:
            branch: '{branch}'
        - 'opnfv-build-ubuntu-defaults'
        - '{installer}-defaults'
        - fuel-project-parameter:
            gs-pathname: '{gs-pathname}'

    scm:
        - git-scm

    wrappers:
        - ssh-agent-wrapper
        - timeout:
            timeout: 360
            fail: true

    triggers:
        - gerrit:
            server-name: 'gerrit.opnfv.org'
            trigger-on:
                - change-merged-event
                - comment-added-contains-event:
                    comment-contains-value: 'remerge'
            projects:
              - project-compare-type: 'ANT'
                project-pattern: '{project}'
                branches:
                    - branch-compare-type: 'ANT'
                      branch-pattern: '**/{branch}'
                file-paths:
                  - compare-type: ANT
                    pattern: 'ci/**'
                  - compare-type: ANT
                    pattern: 'build/**'
                  - compare-type: ANT
                    pattern: 'deploy/**'
                forbidden-file-paths:
                  - compare-type: ANT
                    pattern: 'docs/**'

    builders:
        - shell:
            !include-raw-escape: ./fuel-build.sh
        - shell:
            !include-raw-escape: ./fuel-upload-artifact.sh
        - shell:
            !include-raw-escape: ./fuel-workspace-cleanup.sh

- job-template:
    name: 'fuel-merge-deploy-virtual-{stream}'

    disabled: true

    concurrent: true

    properties:
        - throttle:
            enabled: true
            max-total: 2
            max-per-node: 1
            option: 'project'
        - build-blocker:
            use-build-blocker: true
            blocking-jobs:
                - 'fuel-os-.*?-virtual-daily-.*'
                - 'fuel-merge-deploy-virtual-.*'
            block-level: 'NODE'

    parameters:
        - project-parameter:
            project: '{project}'
        - gerrit-parameter:
            branch: '{branch}'
        - 'fuel-virtual-defaults':
            installer: '{installer}'
        - '{installer}-defaults'
        - fuel-project-parameter:
            gs-pathname: '{gs-pathname}'
    scm:
        - git-scm

    wrappers:
        - ssh-agent-wrapper

    triggers:
        - gerrit:
            server-name: 'gerrit.opnfv.org'
            trigger-on:
                - change-merged-event
                - comment-added-contains-event:
                    comment-contains-value: 'remerge'
            projects:
              - project-compare-type: 'ANT'
                project-pattern: '{project}'
                branches:
                    - branch-compare-type: 'ANT'
                      branch-pattern: '**/{branch}'
                file-paths:
                  - compare-type: ANT
                    pattern: 'ci/**'
                  - compare-type: ANT
                    pattern: 'build/**'
                  - compare-type: ANT
                    pattern: 'deploy/**'
                forbidden-file-paths:
                  - compare-type: ANT
                    pattern: 'docs/**'
            dependency-jobs: 'fuel-merge-build-{stream}'

    builders:
        - shell:
            !include-raw-escape: ./fuel-download-artifact.sh
        - shell:
            !include-raw-escape: ./fuel-deploy.sh
        - shell:
            !include-raw-escape: ./fuel-workspace-cleanup.sh

    publishers:
        - email:
            recipients: jonas.bjurel@ericsson.com stefan.k.berg@ericsson.com fzhadaev@mirantis.com

- job-template:
    name: 'fuel-deploy-generic-daily-{stream}'

    concurrent: true

    disabled: '{obj:disabled}'

    properties:
        - throttle:
            enabled: true
            max-per-node: 1
            option: 'project'
        - build-blocker:
            use-build-blocker: true
            blocking-jobs:
                - 'fuel-os-.*?-daily-.*'
                - 'fuel-deploy-generic-daily-.*'
            block-level: 'NODE'

    parameters:
        - project-parameter:
            project: '{project}'
        - gerrit-parameter:
            branch: '{branch}'
        - '{installer}-defaults'
        - string:
            name: GIT_BASE
            default: https://gerrit.opnfv.org/gerrit/$PROJECT
            description: 'Git URL to use on this Jenkins Slave'
        - string:
            name: DEPLOY_SCENARIO
            default: 'os-odl_l2-nofeature-ha'
        - node:
            name: SLAVE_NAME
            description: 'Slave name on Jenkins'
            allowed-slaves:
                - ericsson-pod2
                - lf-pod2
                - ericsson-pod1
            default-slaves:
                - ericsson-pod2
        - fuel-project-parameter:
            gs-pathname: '{gs-pathname}'

    scm:
        - git-scm

    wrappers:
        - build-name:
            name: '$BUILD_NUMBER - POD: $NODE_NAME Scenario: $DEPLOY_SCENARIO'

    builders:
        - shell:
            !include-raw-escape: ./fuel-download-artifact.sh
        - shell:
            !include-raw-escape: ./fuel-deploy.sh

########################
# parameter macros
########################
- parameter:
    name: fuel-project-parameter
    parameters:
        - string:
            name: BUILD_DIRECTORY
            default: $WORKSPACE/build_output
            description: "Directory where the build artifact will be located upon the completion of the build."
        - string:
            name: CACHE_DIRECTORY
            default: $HOME/opnfv/cache/$INSTALLER_TYPE
            description: "Directory where the cache to be used during the build is located."
        - string:
            name: GS_URL
            default: artifacts.opnfv.org/$PROJECT{gs-pathname}
            description: "URL to Google Storage."