-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
47 lines (47 loc) · 1.7 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
pipeline {
agent any
environment {
DOCKER_IMAGE = 'sherifs82/myapi:v1'
DOCKER_REGISTRY = 'https://index.docker.io/v1/'
DOCKER_REGISTRY_CREDENTIALS_ID = 'dockerHubCreds'
}
stages {
stage('Setup kubectl') {
steps {
script {
if (sh(script: 'which kubectl', returnStatus: true) != 0) {
sh '''
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
mkdir -p ~/bin
mv ./kubectl ~/bin/
'''
}
}
}
}
stage('Build and Publish Docker Image') {
steps {
script {
dockerBuildAndPublish {
registryUrl "${DOCKER_REGISTRY}"
registryCredentialsId "${DOCKER_REGISTRY_CREDENTIALS_ID}"
repositoryName "${DOCKER_IMAGE}"
tag "${env.BUILD_ID}"
dockerFile "Dockerfile" // Corrected the case and parameter usage here
buildContext "."
}
}
}
}
stage('Deploy to Kubernetes') {
steps {
script {
withKubeConfig(credentialsId: 'jenkins-k8s-sa', serverUrl: 'https://917f0e0a-ab07-4b94-a298-c72a87ee6446.k8s.ondigitalocean.com') {
sh '~/bin/kubectl apply -f myapi-kubernetes.yaml --validate=false'
}
}
}
}
}
}