100 Days of Devops day 81 Jenkins Multistage pipeline checker issue

Hey team,

The checker is expecting a random string every retry — that’s the problem. First time ‘x2pak7d5ycaa’, then different ones each time. But the task just wants “Welcome to xFusionCorp Industries” on the load balancer, and it is showing exactly that.

I tried 4 times:

  • index.html updated correctly
  • Pipeline deploys to /var/www/html
  • curl test passes
  • Build says SUCCESS
  • Page looks perfect

Still fails because of the random string check.





Can you please check it?

Thanks!
Thisal

The requirements of the task have changed.

Add App Server 1 as a Jenkins agent (slave) node: name App Server 1 , label stapp01 , remote root directory /home/sarah/jenkins_agent , launch via SSH with host stapp01 and credentials for user sarah . Install java-17-openjdk on App Server 1 if needed.

I have the same issue, do anyone have a proper solution?? :melting_face:

I have the same issue, do anyone have a proper solution?? :melting_face:

The task specifically asks for the content to be “Welcome to xFusionCorp Industries”.
If the validator changes the Gitea repo to a random string, and your Test stage is hardcoded to look for “Welcome to xFusionCorp Industries”, the grep command will fail every time.

To pass a validator that changes the source code, your Test stage shouldn’t look for a hardcoded string. Instead, it should compare what is on the website to what is in the local repository.

Update the Pipeline script to this “Dynamic” version:

pipeline {
    agent { label 'stapp01' }
    
    stages {
        stage('Deploy') {
            steps {
                script {
                    def giteaUrl = "http://sarah:Sarah_pass123@gitea:3000/sarah/web.git"
                    sh """
                        # 1. Ownership & Safety
                        echo 'Sarah_pass123' | sudo -S chown -R sarah:sarah /var/www/html
                        git config --global --add safe.directory /var/www/html
                        
                        # 2. Sync with Gitea
                        cd /var/www/html
                        git remote set-url origin ${giteaUrl}
                        git fetch origin master
                        git reset --hard origin/master
                        
                        # 3. Permissions for Web Server
                        echo 'Sarah_pass123' | sudo -S chmod -R 755 /var/www/html
                    """
                }
            }
        }
        
        stage('Test') {
            steps {
                script {
                    // DYNAMIC TEST: Compare the website content to the file on disk
                    // If they match, the deployment was successful regardless of the text
                    sh """
                        # Get content from the Load Balancer
                        WEB_CONTENT=\$(curl -sL http://stlb01:8091)
                        
                        # Get content from the actual file
                        FILE_CONTENT=\$(cat /var/www/html/index.html)
                        
                        echo "Web says: \$WEB_CONTENT"
                        echo "File says: \$FILE_CONTENT"
                        
                        if [ "\$WEB_CONTENT" == "\$FILE_CONTENT" ]; then
                            echo "Validation Success: Website matches Repository"
                        else
                            echo "Validation Failure: Website does not match Repository"
                            exit 1
                        fi
                    """
                }
            }
        }
    }
}
1 Like

I really appreciate the explanation! Using a dynamic check instead of a hardcoded string solved it. Task complete!

Glad that it helped.

still facing same issue kindly explain it how to perform this lab.?

see if this helps you

Thanks for your solution, it helps :clap: