|
|
@@ -35,18 +35,6 @@ node {
|
|
|
}
|
|
|
|
|
|
stage('Build Deploy '){
|
|
|
- // // now you are on slave labeled with 'label'
|
|
|
- // def workspace = WORKSPACE
|
|
|
- // // ${workspace} will now contain an absolute path to job workspace on slave
|
|
|
-
|
|
|
- // workspace = env.WORKSPACE
|
|
|
- // // ${workspace} will still contain an absolute path to job workspace on slave
|
|
|
-
|
|
|
- // // When using a GString at least later Jenkins versions could only handle the env.WORKSPACE variant:
|
|
|
- // echo "Current workspace is ${env.WORKSPACE}"
|
|
|
-
|
|
|
- // // the current Jenkins instances will support the short syntax, too:
|
|
|
- // echo "Current workspace is $WORKSPACE"
|
|
|
docker.withTool("myDocker"){
|
|
|
docker.withRegistry(registryAddress, registryCredential) {
|
|
|
|
|
|
@@ -57,28 +45,38 @@ node {
|
|
|
dockerImage.push('latest')
|
|
|
}
|
|
|
}
|
|
|
- // echo 'env.BRANCH_NAME : ' + env.BRANCH_NAME
|
|
|
- // if(env.BRANCH_NAME == 'master'){
|
|
|
- // script {
|
|
|
- // app = docker.build("ptb-be:latest")
|
|
|
- // echo 'app content : ' + app
|
|
|
- // dockerImage = registryAddress + ":$BUILD_NUMBER"
|
|
|
- // echo 'dockerImage : ' + dockerImage
|
|
|
- // echo 'registryCredential : ' + registryCredential
|
|
|
- // echo 'registryAddress : ' + registryAddress
|
|
|
- // echo 'withRegistry running...'
|
|
|
- // docker.withRegistry( "http://"+registryAddress, registryCredential ) {
|
|
|
- // echo 'withRegistry inside... app.push start'
|
|
|
- // //app.push("${BUILD_NUMBER}")
|
|
|
- // app.push('ptb-be:latest')
|
|
|
- // echo 'app.push done'
|
|
|
- // echo 'withRegistry inside... app.push latest start'
|
|
|
- // app.push(latest)
|
|
|
- // echo 'withRegistry inside... app.push latest done'
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
+ }
|
|
|
|
|
|
+ stage('Deploy to Server'){
|
|
|
+ // Deploy menggunakan Docker plugin via SSH dengan docker-compose
|
|
|
+ // Pastikan SSH credential sudah dikonfigurasi di Jenkins
|
|
|
+ // Credential ID: 'Server-SSH-ID' (SSH Username with private key)
|
|
|
+
|
|
|
+ def serverDockerHost = 'ssh://root@000-sidali.kemdiktisaintek.go.id'
|
|
|
+ def sshCredential = 'Server-SSH-ID' // SSH credential (Username with private key)
|
|
|
+ def imageName = '000-sidali.kemdiktisaintek.go.id/ptb-be:latest'
|
|
|
+ def composeDir = '/path/to/docker-compose' // Sesuaikan dengan path docker-compose.yml di server
|
|
|
+
|
|
|
+ docker.withTool('myDocker') {
|
|
|
+ // Connect ke remote Docker daemon via SSH
|
|
|
+ docker.withServer(serverDockerHost, sshCredential) {
|
|
|
+ // Login ke registry untuk pull image
|
|
|
+ docker.withRegistry(registryAddress, registryCredential) {
|
|
|
+ // Pull image terbaru
|
|
|
+ sh "docker pull ${imageName}"
|
|
|
+
|
|
|
+ // Deploy menggunakan docker-compose
|
|
|
+ sh """
|
|
|
+ cd ${composeDir} && \
|
|
|
+ docker-compose stop ptb-be && \
|
|
|
+ docker-compose rm -f ptb-be && \
|
|
|
+ docker-compose up -d ptb-be
|
|
|
+ """
|
|
|
+
|
|
|
+ echo "Deploy completed successfully"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
catch (err) {
|