-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.groovy
More file actions
44 lines (35 loc) · 1.85 KB
/
script.groovy
File metadata and controls
44 lines (35 loc) · 1.85 KB
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
def ImagePushDockerHub() {
withCredentials([usernamePassword(credentialsId: 'docker', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh '''
echo "$PASS" | docker login -u "$USER" --password-stdin
docker tag ${IMAGE_NAME}:${VERSION} ${DOCKER_USER}/${IMAGE_NAME}:${VERSION}
docker push ${DOCKER_USER}/${IMAGE_NAME}:${VERSION}
'''
}
}
def BuildProject() {
echo "Building Docker image with version: ${env.VERSION}"
sh "docker build -t ${IMAGE_NAME}:${env.VERSION} ."
}
def GitCommit(){
withCredentials([usernamePassword(credentialsId: 'githubpat-key', passwordVariable: 'PASS', usernameVariable: 'USER')]) { //github access key need to get anf after jenkins cedination add username and password(key)
sh '''
git config --global user.email "jenkins@hashan.com"
git config --global user.name "Jenkins"
git remote set-url origin https://${USER}:${PASS}@github.com/hashanCB/mySongs.git
git add -A
git diff --staged --quiet || git commit -m "ci: version bump [ci skip]"
git push origin HEAD:main
'''
}
}
def GitIncrementVersion () {
// Increment package version
sh 'npm version patch --no-git-tag-version'
// Ensure Jenkins reads the updated file
sleep(2)
// Read updated package.json and extract the version correctly
env.VERSION = sh(script: "node -p \"require('./package.json').version\"", returnStdout: true).trim()
echo "New version: ${env.VERSION}"
}
return this