aboutsummaryrefslogtreecommitdiff
path: root/lkft-generic-build-gitlab.yaml
blob: c002cae9d53cde53b5ca2fea6772c115b4036729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
- job:
    name: lkft-generic-build-gitlab
    project-type: freestyle
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            android-internal:
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 180
            num-to-keep: 450
            artifact-num-to-keep: 1
    parameters:
        - string:
            name: BUILD_DIR
            default: lkft
        - string:
            name: ANDROID_BUILD_CONFIG
            default: ''
        - string:
            name: KERNEL_DESCRIBE
        - string:
            name: KERNEL_BRANCH
        - string:
            name: SRCREV_kernel
        - string:
            name: BUILD_REFERENCE_IMAGE_GZ_URL
        - string:
            name: MAKE_KERNELVERSION
        - string:
            name: TEST_OTHER_PLANS_OVERRIDE
            default: ""
        - string:
            name: ANDROID_BUILD_CONFIG_TO_BE_TRIGGERED
            default: ""
        - string:
            name: GITLAB_CALLBACK_URL
            default: ""
        - string:
            name: UPSTREAM_PIPELINE_URL
            default: ""
    disabled: false
    node: docker-bionic-android-lkft
    display-name: 'Generic CI Job to be triggered from gitlab'
    concurrent: true
    wrappers:
        - timestamps
        - build-name:
            name: '#${BUILD_NUMBER}-${KERNEL_DESCRIBE}-${KERNEL_BRANCH}-${ANDROID_BUILD_CONFIG}'
        - timeout:
            timeout: 500
        - credentials-binding:
            - text:
                credential-id: ARTIFACTORIAL_TOKEN
                variable: ARTIFACTORIAL_TOKEN
            - text:
                credential-id: GITLAB_API_LKFT_TOKEN
                variable: GITLAB_API_TOKEN
    builders:
        - shell:
            !include-raw: lkft/common/builders-v2.sh
        - linaro-publish-token
        - shell:
            !include-raw: lkft/common/publisher-v2.sh
        - shell: |
            #!/bin/bash -ex
            env

            PUB_DEST="android/lkft/${JOB_NAME}/${BUILD_NUMBER}"
            DOWNLOAD_URL="http://snapshots.linaro.org/${PUB_DEST}"

            f_build_json="build.json"
            cat >"${f_build_json}" <<__EOF__
            {
                "BUILD_URL": "${BUILD_URL}",
                "BUILD_NUMBER": "${BUILD_NUMBER}",
                "JOB_URL": "${JOB_URL}",
                "DOWNLOAD_URL": "${DOWNLOAD_URL}",
                "ANDROID_BUILD_CONFIG_TO_BE_TRIGGERED": "${ANDROID_BUILD_CONFIG_TO_BE_TRIGGERED}",
                "ANDROID_BUILD_CONFIG": "${ANDROID_BUILD_CONFIG}",
                "TEST_OTHER_PLANS_OVERRIDE": "${TEST_OTHER_PLANS_OVERRIDE}",
                "BUILD_REFERENCE_IMAGE_GZ_URL": "${BUILD_REFERENCE_IMAGE_GZ_URL}",
                "KERNEL_DESCRIBE": "${KERNEL_DESCRIBE}",
                "KERNEL_BRANCH": "${KERNEL_BRANCH}",
                "SRCREV_kernel": "${SRCREV_kernel}",
                "MAKE_KERNELVERSION": "${MAKE_KERNELVERSION}"
            }
            __EOF__

    publishers:
        - postbuildscript:
           builders:
             - role: SLAVE
               build-on:
                 - SUCCESS
                 - UNSTABLE
                 - FAILURE
                 - NOT_BUILT
                 - ABORTED
               build-steps:
                 - shell: |
                    #!/bin/bash -ex
                    # call gitlab api to notify the gitlab pipeline side that the build is finished successfully or not
                    # only when the GITLAB_API_TOKEN and GITLAB_CALLBACK_URL are available
                    if [ -n "${GITLAB_API_TOKEN}" ] && [ -n "${GITLAB_CALLBACK_URL}" ]; then
                        cat >"variables.json" <<__EOF__
                    {
                      "job_variables_attributes": [
                        {
                          "key": "JENKINS_BUILD_URL",
                          "value": "${BUILD_URL}"
                        }
                      ]
                    }
                    __EOF__

                        # https://docs.gitlab.com/ee/api/jobs.html#run-a-job
                        curl --request POST \
                             --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" \
                             "${GITLAB_CALLBACK_URL}" \
                             --data @variables.json
                    fi
        - archive:
            artifacts: '*.xml,*.json,*.txt'
            latest-only: true
        - email:
            recipients: 'lkft-maintainers@lists.linaro.org'