summarylogtreecommitdiffstats
path: root/Jenkinsfile
blob: baf90e36a7455c4fec67cb9e70974a65514c2f4d (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
/* groovylint-disable GStringExpressionWithinString, LineLength */
pipeline {
    agent any
    environment {
        VERSION = """${sh(
                returnStdout: true,
                script: "curl https://api.github.com/repos/elastic/logstash/releases/latest | jq -r '.tag_name' | cut -c2- | tr -d '\n'"
            )}"""
    }
    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }
        stage('Update PKGBUILD') {
            steps {
                sh '''
                    sed -ie "s|pkgver=.*$|pkgver=${VERSION}|g" PKGBUILD
                    rm PKGBUILDe
                '''
            }
        }
        stage('Update Checksums') {
            steps {
                sh '''
                    updpkgsums
                '''
            }
        }
        stage('Make Package') {
            steps {
                sh '''
                    makepkg -s
                '''
            }
        }
        stage('Generate .SRCINFO') {
            steps {
                sh '''
                    makepkg --printsrcinfo > .SRCINFO
                '''
            }
        }
        stage('Cleanup - makepkg Artifacts') {
            steps {
                sh '''
                    rm -rf pkg src logstash-8*
                '''
            }
        }
        stage('Git Push') {
            steps {
                withCredentials([sshUserPrivateKey(credentialsId: "Arch_AUR", keyFileVariable: 'KEY')]) {
                    sh '''
                        git config user.email "aman.iv0012@gmail.com"
                        git config user.name "Aman Gupta"
                        export GIT_SSH_COMMAND="ssh -i $KEY"
                        git branch release
                        git checkout master
                        git merge release
                        git remote add ssh-origin ssh://aur@aur.archlinux.org/logstash.git
                        git commit -am "Automated Release: Updated to v${VERSION}"
                        git push ssh-origin master
                    '''
                }
            }
        }
    }
    post {
        always {
            echo "Always Run"
            // deleteDir() /* clean up our workspace */
        }
        success {
            withCredentials([string(credentialsId: 'Discord_Webhook', variable: 'WEBHOOK_URL')]) {
                sh '''
                    curl -H 'Content-Type: application/json' -d '{\"content\": \"✅ Logstash v'"$VERSION"' Released to AUR 🎆\"}' ${WEBHOOK_URL}
                '''
            }
        }
        failure {
            withCredentials([string(credentialsId: 'Discord_Webhook', variable: 'WEBHOOK_URL')]) {
                sh '''
                    curl -H 'Content-Type: application/json' -d '{\"content\": \"❌ Logstash v'"$VERSION"' Pipeline Failed 🛠️\"}' ${WEBHOOK_URL}
                '''
            }
        }
    }
}