File size: 4,041 Bytes
b585c7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils

properties(
    [
        parameters(
            [
                string(name: 'BRANCH_TAG', defaultValue: 'origin/main'),
                booleanParam(name: 'AZURE', defaultValue: true, description: 'Make Azure Machine Image/Not?'),
                booleanParam(name: 'GCP', defaultValue: true, description: 'Make GCP Image/Not?'),
                string(name: 'H2OGPT_VERSION', defaultValue: "010", description: 'Example: for version 1.10.5 use 1105')
            ]
        )
    ]
)

node('linux && docker') {
    stage('Init') {
        cleanWs()
        currentBuild.displayName = "#${BUILD_NUMBER} - Rel:${H2OGPT_VERSION}"
        checkout scm
        sh('ls -al')
    }

    stage('Build Images') {
        try {
            docker.image('harbor.h2o.ai/opsh2oai/h2oai-packer-build:2').inside {
                parallel([
                        "GCP Ubuntu 20.04": {
                            withCredentials([file(credentialsId: 'GCP_MARKETPLACE_SERVICE_ACCOUNT', variable: 'GCP_ACCOUNT_FILE')]) {
                                dir('cloud/packer') {
                                    if (params.GCP) {
                                        sh("packer build \
                                            --force \
                                            -var 'project_id=h2o-gce' \
                                            -var 'account_file=$GCP_ACCOUNT_FILE' \
                                            -var 'h2ogpt_version=${H2OGPT_VERSION}' \
                                            -var 'branch_tag=${BRANCH_TAG}' \
                                            h2ogpt-gcp.json"
                                        )
                                        archiveArtifacts artifacts: '*-image-info.json'
                                    }else {
                                        Utils.markStageSkippedForConditional('GCP Ubuntu 20.04')
                                    }
                                }
                            }
                        },

                         "AZURE Ubuntu 20.04": {
                            withCredentials([string(credentialsId: "AZURE_MARKETPLACE_CLIENT_ID", variable: "AZURE_CLIENT_ID"),
                                             string(credentialsId: "AZURE_MARKETPLACE_CLIENT_SECRET", variable: "AZURE_CLIENT_SECRET"),
                                             string(credentialsId: "AZURE_MARKETPLACE_SUBSCRIPTION_ID", variable: "AZURE_SUBSCRIPTION_ID"),
                                             string(credentialsId: "AZURE_MARKETPLACE_TENANT_ID", variable: "AZURE_TENANT_ID")]) {
                                dir('cloud/packer') {
                                    if (params.AZURE) {
                                        sh("packer build \
                                            --force \
                                            -var 'client_id=$AZURE_CLIENT_ID' \
                                            -var 'client_secret=$AZURE_CLIENT_SECRET' \
                                            -var 'managed_image_resource_group_name=H2OIMAGES' \
                                            -var 'subscription_id=$AZURE_SUBSCRIPTION_ID' \
                                            -var 'tenant_id=$AZURE_TENANT_ID' \
                                            -var 'h2ogpt_version=${H2OGPT_VERSION}' \
                                            -var 'branch_tag=${BRANCH_TAG}' \
                                            h2ogpt-azure.json"
                                        )
                                        archiveArtifacts artifacts: '*-image-info.json'
                                    }else {
                                        Utils.markStageSkippedForConditional('AZURE Ubuntu 20.04')
                                    }
                                }
                            }
                        },

                ])
            }
        } finally {
            cleanWs()
        }
    }
}