-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsfile
38 lines (36 loc) · 1.58 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
pipeline {
// agent { label 'jenkins-agent' }
agent any
stages {
stage('Build and Test') {
steps {
echo 'building and testing...'
nodejs(nodeJSInstallationName: 'NodeJS') {
// Install pnpm globally, clean cache, and install dependencies
sh 'npm install -g pnpm'
sh 'npm cache clean --force'
sh 'pnpm install --store=node_modules/.pnpm-store'
sh 'pnpm run test'
}
}
}
stage('Deploy') {
tools { dockerTool 'DockerInstall'}
steps {
echo 'Deploying...'
withCredentials([usernamePassword(credentialsId: 'myDockerID', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh 'docker login -u "${DOCKER_USERNAME}" -p "${DOCKER_PASSWORD}" https://index.docker.io/v1/'
sh 'docker build -t ${DOCKER_USERNAME}/${GITHUB_REPO_NAME}:v${BUILD_NUMBER} -f dockerfile .'
sh 'docker push ${DOCKER_USERNAME}/${GITHUB_REPO_NAME}:v${BUILD_NUMBER}'
echo 'Deployed! Proceeding to delete the built container...'
sh 'docker rmi ${DOCKER_USERNAME}/${GITHUB_REPO_NAME}:v${BUILD_NUMBER}'
}
}
}
stage('Done') {
steps {
echo 'Done!'
}
}
}
}