0

I have been trying for days to try and get my jenkins pipeline to work, I was already able to execute tests via docker on my local using cmd lines. However when trying to do the same steps on jenkins it keeps on failing. Is there any way anyone could possibly provide an example of working jenkins pipeline script (regardless of using dockerfile to build the image or by using the docker image on dockerhub) that is able to generate reports within the docker container.

Reference : git - https://seleniumbase.io/integrations/docker/ReadMe/ Dockerfile - https://github.com/seleniumbase/SeleniumBase/blob/master/Dockerfile

Here is what i have been working with :

    node {
    git 'https://gitlab.com/username/repo.git'

    def myEnv = docker.build 'seleniumbase:1'

    // Run tests inside the Docker container
    def containerName = 'sbase-container'
    def testCommand = 'pytest'  // Replace with your actual test command
    def testCommand2 = "--var1=username' --var2='password' --dashboard --html=/SeleniumBase/examples/reports-generated/report.html  --browser=chrome --headless"


    try {
        def container = myEnv.run("-i -t --name ${containerName}")
        container.inside {
        bat './run_script.sh'
        }
    } finally {
        // Clean up the Docker container
        bat "docker stop ${containerName}"  // Use 'bat' step for Windows
        bat "docker rm ${containerName}"  // Use 'bat' step for Windows
    }
}

Thank you so much in advance. Do let me know if there is any other information required.

1 Answers1

0

Based on https://www.jenkins.io/doc/book/pipeline/jenkinsfile/ examples, here's a possible Jenkinsfile script that assumes Python and pip are already installed (and Chrome):

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                pip install -U seleniumbase
            }
        }
        stage('Test') {
            steps {
                pytest --dashboard --html=report.html -s --headless
            }
        }
    }
}

Here's an outside resource I found regarding pytest and Jenkinsfile:

Since you're using seleniumbase as a pytest plugin, the real focus should be on running pytest from your Jenkins environments, which will be enough to run SeleniumBase tests.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48