forked from jenkins-docs/simple-python-pyinstaller-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
56 lines (48 loc) · 2.3 KB
/
Jenkinsfile
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
node(){
stage('Build') {
checkout scm
sh 'python3 -m py_compile sources/add2vals.py sources/calc.py'
stash(name: 'compiled-results', includes: 'sources/*.py*')
}
stage('Test') {
docker.image('qnib/pytest').inside {
sh 'py.test --junit-xml test-reports/results.xml sources/test_calc.py'
}
}
stage('Manual Approval'){
input message: 'Lanjutkan ke tahap Deploy?'
}
stage('Deploy') {
withCredentials([string(credentialsId: 'vercel-credentials', variable: 'VERCEL_TOKEN')]) {
withEnv(['VOLUME=$(pwd)/sources:/src', 'IMAGE=cdrx/pyinstaller-linux:python3']) {
dir(path: env.BUILD_ID) {
unstash name: 'compiled-results'
sh "docker run --rm -v ${VOLUME} ${IMAGE} 'pyinstaller -F add2vals.py'"
archiveArtifacts "sources/dist/add2vals"
echo 'Debug information:'
sh "ls -la /var/jenkins_home/workspace/submission-cicd-pipeline-aikyodzakia/181/sources/dist"
dir("sources/dist") {
sh "ls -la"
// Check if the project exists on Vercel
def projectExists = sh(script: "vercel --token=\${VERCEL_TOKEN} inspect .", returnStatus: true)
// memberi akses read write execute ke user jenkins
sh "sudo chmod -R -u+rwx ."
sh "sudo chown -R jenkins:jenkins ."
// membuat add2vals menjadi executable
sh "sudo chmod a+x add2vals"
// Deploy or redeploy based on project existence
if (projectExists == 0) {
echo "Vercel project exists. Triggering redeploy..."
sh "vercel --token=\${VERCEL_TOKEN} --prod --confirm . -y"
} else {
echo "Vercel project does not exist. Deploying for the first time..."
sh "vercel --token=\${VERCEL_TOKEN} --prod . -y"
}
}
echo 'Kriteria 3, tunggu 1 menit...'
sh 'sleep 60'
}
}
}
}
}