Task 78 validation fails

Day 78: Jenkins Conditional Pipeline

I have executed the Jenkins pipeline script. the script works fine when I tested from jenkins UI.
for both conditions master and feature, it runs as expected.

But it fails during the lab validation when condition is featuring branch, I observed that there is a change happening in the repository where feature file is getting replaced by a validation file , and the lab fails with error “feature file not found on the app server” , cause the file is getting deleted during the validation … this is the script

pipeline {
agent { label ‘stapp01’ }

stages {
    stage('Deploy') {
        steps {
            script {
                if (params.BRANCH == 'master') {
                    echo "Deploying master branch..."
                    checkout([$class: 'GitSCM',
                        branches: [[name: '*/master']],
                        userRemoteConfigs: [[url: 'http://gitea:3000/sarah/web_app.git']]
                    ])
                } else if (params.BRANCH == 'feature') {
                    echo "Deploying feature branch..."
                    checkout([$class: 'GitSCM',
                        branches: [[name: '*/feature']],
                        userRemoteConfigs: [[url: 'http://gitea:3000/sarah/web_app.git']]
                    ])
                } else {
                    error "Unsupported branch: ${params.BRANCH}. Use 'master' or 'feature'."
                }

                // Copy code into Apache document root
                sh '''
                sudo rm -rf /var/www/html/*
                sudo cp -r * /var/www/html/
                curl -s http://localhost:8080
                '''
            }
        }
    }
}

}

TBH, I’m not sure why your script would work. Most people call git directly in script blocks, which does work, assuming that you’ve set up the agent on stapp01 correctly. You may want to look at this discussion here, which covers different aspects of how to solve this task. In particular – make sure you’re actually pulling the repo at some point of your script.

the script was able to pull the repo; the issue occurs during the validation. where the feature file is getting replaced with some validation file on the repo.so the lab fails, as it not able to place the feature file in the app server since it is not available anymore on the repo. I will try the other solutions to see if they work, thanks.

just tried the other solution, it worked, Thanks …it was cloning the repo to a different directory and then moving those files to the main directory.

for further tasks if you face any issue explore my solutions and don’t forget to star my repo :blush: .