From 712f627a9501382851d975e1b28b9ee9470d4d78 Mon Sep 17 00:00:00 2001 From: Reza Behzadan Date: Sun, 31 Mar 2024 12:05:00 +0330 Subject: [PATCH] Update Jenkinsfile --- Jenkinsfile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 28647b9..39ec9ad 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,11 +2,59 @@ pipeline { agent { docker { image 'golang:1.22.1' } } + environment { + GITEA_API_TOKEN = credentials('git.behzadan.ir') + } stages { + stage('Build') { + steps { + sh 'make build' + } + } + stage('Test') { steps { sh 'make test' } } + + stage('Package') { + steps { + sh 'make package' + } + } + + stage('Upload Release') { + steps { + script { + def repoOwner = 'reza' + def repoName = 'go-hello-world' + def tagName = 'v1.0.0' + def releaseTitle = 'v1.0.0' + def releaseDescription = 'v1.0.0' + def zipFile = 'hello-world.zip' + + def createReleaseCmd = """ + curl -X POST -H "Content-Type: application/json" -H "Authorization: token ${GITEA_API_TOKEN}" \\ + -d '{ "tag_name": "${tagName}", "target_commitish": "main", "name": "${releaseTitle}", "body": "${releaseDescription}", "draft": false, "prerelease": false }' \\ + "https://git.behzadan.ir/api/v1/repos/${repoOwner}/${repoName}/releases" + """ + sh createReleaseCmd + + def uploadAssetCmd = """ + curl -X POST -H "Authorization: token ${GITEA_API_TOKEN}" -H "Content-Type: application/zip" \\ + --data-binary @${zipFile} \\ + "https://git.behzadan.ir/api/v1/repos/${repoOwner}/${repoName}/releases/${tagName}/assets?name=${zipFile}" + """ + sh uploadAssetCmd + } + } + } + + stage('Cleanup') { + steps { + sh 'make clean' + } + } } }