Day 77: Jenkins Deploy Pipeline

I successfuly implemented the pipeline but still got and error during the submission.
Below are the artefacts:


================== console output after deployment ===================
Started by user admin

[Pipeline] Start of Pipeline
[Pipeline] node
Running on Storage Server
in /var/www/html/workspace/devops-webapp-job
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Deploy)
[Pipeline] script
[Pipeline] {
[Pipeline] sh

  • rm -rf /home/natasha/web_app_deploy
  • git clone http://git.stratos.xfusioncorp.com/sarah/web_app.git /home/natasha/web_app_deploy
    Cloning into ‘/home/natasha/web_app_deploy’…
  • rsync -av --delete --exclude=workspace /home/natasha/web_app_deploy/ /var/www/html/
    sending incremental file list
    deleting caches/durable-task/
    deleting caches/
    index.html
    .git/
    .git/HEAD
    .git/config
    .git/description
    .git/index
    .git/packed-refs
    .git/branches/
    .git/hooks/
    .git/hooks/applypatch-msg.sample
    .git/hooks/commit-msg.sample
    .git/hooks/fsmonitor-watchman.sample
    .git/hooks/post-update.sample
    .git/hooks/pre-applypatch.sample
    .git/hooks/pre-commit.sample
    .git/hooks/pre-merge-commit.sample
    .git/hooks/pre-push.sample
    .git/hooks/pre-rebase.sample
    .git/hooks/pre-receive.sample
    .git/hooks/prepare-commit-msg.sample
    .git/hooks/push-to-checkout.sample
    .git/hooks/sendemail-validate.sample
    .git/hooks/update.sample
    .git/info/
    .git/info/exclude
    .git/logs/
    .git/logs/HEAD
    .git/logs/refs/
    .git/logs/refs/heads/
    .git/logs/refs/heads/master
    .git/logs/refs/remotes/
    .git/logs/refs/remotes/origin/
    .git/logs/refs/remotes/origin/HEAD
    .git/objects/
    .git/objects/info/
    .git/objects/pack/
    .git/objects/pack/pack-afc7c81a350dd63e9973f69db8db55ee75822275.idx
    .git/objects/pack/pack-afc7c81a350dd63e9973f69db8db55ee75822275.pack
    .git/objects/pack/pack-afc7c81a350dd63e9973f69db8db55ee75822275.rev
    .git/refs/
    .git/refs/heads/
    .git/refs/heads/master
    .git/refs/remotes/
    .git/refs/remotes/origin/
    .git/refs/remotes/origin/HEAD
    .git/refs/tags/

sent 31,593 bytes received 678 bytes 64,542.00 bytes/sec
total size is 28,976 speedup is 0.90

  • rm -rf /home/natasha/web_app_deploy
  • echo ‘Deployment completed successfully’
    Deployment completed successfully
    [Pipeline] }
    [Pipeline] // script
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    Finished: SUCCESS

Read the error carefully it will tell why submission is not accepted.

This particular one really stressed me, you can use this my script and see if it will help.

pipeline {
agent {
label ‘ststor01’
}

parameters {
    string(name: 'BRANCH', defaultValue: 'master', description: 'Branch to deploy (master or feature)')
}

stages {
    stage('Deploy') {
        steps {
            script {
                if (params.BRANCH != 'master' && params.BRANCH != 'feature') {
                    error("Invalid BRANCH parameter. Only 'master' or 'feature' are allowed.")
                }
                
                echo "Deploying ${params.BRANCH} branch..."
                
                // Remove any lock files and force deployment
                sh """
                    sudo rm -f /var/www/html/.git/index.lock
                    sudo rm -f /var/www/html/.git/HEAD.lock
                    cd /var/www/html
                    sudo git config --global --add safe.directory /var/www/html
                    sudo git fetch --all
                    sudo git checkout --force ${params.BRANCH}
                    sudo git reset --hard origin/${params.BRANCH}
                    sudo git pull origin ${params.BRANCH}
                """
                
                echo "Successfully deployed ${params.BRANCH} branch!"
            }
        }
    }
}

post {
    always {
        echo "Pipeline execution finished"
    }
}

}