jenkinsci / allure-plugin

Allure Jenkins Plugin
https://plugins.jenkins.io/allure-jenkins-plugin/
Other
84 stars 63 forks source link

Cannot run allure in jenkins pipeline with docker agent #286

Closed KevinLuc95 closed 3 years ago

KevinLuc95 commented 3 years ago

Reproduction steps

currently, i'm running the e2e automation test in Jenkins pipeline and I cannot generate report inside jenkins pipeline. Please help


/* groovylint-disable-next-line CompileStatic */
pipeline {
    agent {
        docker {
            image 'mcr.microsoft.com/playwright:bionic'
            label 'container-host'
        }
    }
    triggers {
        cron('0 8 * * *')
    }
    options {
        timeout(time: 1, unit: 'HOURS')
        retry(1)
        buildDiscarder(logRotator(numToKeepStr: '30', daysToKeepStr: '90'))
        timestamps()
        ansiColor('xterm')
    }
    stages {
        stage('Build') {
            steps {
                sh 'yarn install'
            }
        }
        stage('Test') {
            steps {
                sh 'yarn test'
            }
        }

        stage('Generate Allure Reports') {
            steps {
                script {
                    try {
                        allure([
                    includeProperties: false,
                    jdk: '',
                    properties: [],
                    reportBuildPolicy: 'ALWAYS',
                    results: [[path: "${env.WORKSPACE}/allure-results"]]
                ])
                } catch (e) {
                    }
                }
            }
        }
    }

    post {
        always {
            junit '**/reports/*.xml'
        }
    }
}```

### Results

Expected result:

<!-- What was your expected result? -->

Actual result:

```16:16:32  [SG-Web-Automation-Test] $ docker exec --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** --env ******** 40129016e5f8d0cf6315e4a5987493fe04fd6d1cc3bfdf358ae98f5a3025a7d6 /home/ec2-user/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure260/bin/allure generate -c -o /home/ec2-user/workspace/SG-Web-Automation-Test/allure-report
16:16:33  OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"/home/ec2-user/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure260/bin/allure\": stat /home/ec2-user/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure260/bin/allure: no such file or directory": unknown
Error when executing always post condition:
ru.yandex.qatools.allure.jenkins.exception.AllurePluginException: Can not generate Allure Report, exit code: 126
    at ru.yandex.qatools.allure.jenkins.AllureReportPublisher.generateReport(AllureReportPublisher.java:314)
    at ru.yandex.qatools.allure.jenkins.AllureReportPublisher.perform(AllureReportPublisher.java:231)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:116)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)```
KevinLuc95 commented 3 years ago

I've solve problem

lrpaquet commented 3 years ago

@KevinLuc95

I've solve problem

What was your solution?

KevinLuc95 commented 3 years ago

@lrpaquet-jive I missing tash and unstash allure-result and also run it inside Docker, after realizing I separate step generate report to outside Docker


        stage('Build & Run Test') {
            agent {
                docker {
                    reuseNode true
                    image 'mcr.microsoft.com/playwright:bionic'
                }
            }
            stages {
                stage('Build') {
                    steps {
                        sh 'yarn install'
                    }
                }
                stage('Run Test') {
                    steps {
                        script {
                            try {
                                sh 'yarn test ./src/test/smoke/'
                                stash name: 'allure-results', includes: 'allure-results/*'
                                currentBuild.result = 'SUCCESS'
                            } catch (e) {
                                stash name: 'allure-results', includes: 'allure-results/*'
                                currentBuild.result = 'FAILED'
                                throw e
                            }
                        }
                    }
                }
            }
        }
    }
    post {
        always {
            unstash 'allure-results' //extract results
            script {
                allure([
                includeProperties: false,
                jdk: '',
                properties: [],
                reportBuildPolicy: 'ALWAYS',
                results: [[path: 'allure-results']]
            ])
            }
        }
    }
lrpaquet commented 3 years ago

Hi @KevinLuc95, Thanks for the quick answer!

On my side, I'm still struggling because we're running on a remote slave and, for implementation reasons, I cannot use the tools { } block in the pipeline.

KevinLuc95 commented 3 years ago

@lrpaquet-jive just my own thoughts hope it can help you You can download the Allure command line into a slave before running the test and also using Allure Command-Line to generate the report


stage('Generate Report') {
       steps {
             sh './node_modules/.bin/allure generate ./allure-results'
       }
}
lrpaquet commented 3 years ago

@KevinLuc95 Thanks for the suggestion.

I ended up calling another job which has a vanilla pipeline where I can set tools { } and run directly on the slave(no docker).

Just to clarify the limitation I was facing. I could not execute outside of the docker agent since the pipeline of the job is regulated by a Shared Library.

kiriasCMNH commented 2 years ago

Isn't there another way to make it work other than having to specify the docker agent at stage level on each step? I was able to make it work by using agent any at the pipeline level and then for each stage specifying a docker agent but it became kind of annoying because i had to repeat that block on each stage since im using the same image and args for all of my stages, and if i have it at the pipeline level it fails to run the allure step.

Another alternative i was trying out was using allure command line inside my container and then generate my report at the root of my workspace in the /allure-report folder, it looks exactly the same when browsing through my workspace files when comparing to an old version of my pipeline where i still was not using docker, but now it doesn't display the link to show the allure report, even tho i made sure to generate the output in the expected path and to save the artifact inside the build. It is important to note that in this last attempt i tried not using the plugin and instead just generating the output and persisting it through jenkins in the expected paths.

image

aspenboy commented 6 months ago

@lrpaquet-jive I missing tash and unstash allure-result and also run it inside Docker, after realizing I separate step generate report to outside Docker

        stage('Build & Run Test') {
            agent {
                docker {
                    reuseNode true
                    image 'mcr.microsoft.com/playwright:bionic'
                }
            }
            stages {
                stage('Build') {
                    steps {
                        sh 'yarn install'
                    }
                }
                stage('Run Test') {
                    steps {
                        script {
                            try {
                                sh 'yarn test ./src/test/smoke/'
                                stash name: 'allure-results', includes: 'allure-results/*'
                                currentBuild.result = 'SUCCESS'
                            } catch (e) {
                                stash name: 'allure-results', includes: 'allure-results/*'
                                currentBuild.result = 'FAILED'
                                throw e
                            }
                        }
                    }
                }
            }
        }
    }
    post {
        always {
            unstash 'allure-results' //extract results
            script {
                allure([
                includeProperties: false,
                jdk: '',
                properties: [],
                reportBuildPolicy: 'ALWAYS',
                results: [[path: 'allure-results']]
            ])
            }
        }
    }

I tried exactly your approach with stash/unstash, but I'm still getting the same exception:

OCI runtime exec failed: exec failed: unable to start container process: exec: "/home/ec2-user/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure/bin/allure": stat /home/ec2-user/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure/bin/allure: no such file or directory: unknown
[Pipeline] }
[Pipeline] // script
Error when executing always post condition:
Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 77d4fe76-70e6-4881-a2fe-e62ee440c67d
ru.yandex.qatools.allure.jenkins.exception.AllurePluginException: Can not generate Allure Report, exit code: 126
    at ru.yandex.qatools.allure.jenkins.AllureReportPublisher.generateReport(AllureReportPublisher.java:359)
    at ru.yandex.qatools.allure.jenkins.AllureReportPublisher.perform(AllureReportPublisher.java:269)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

Anyone any ideas what might be wrong? All the files are generated (I even tried downloading them and I'm able to generate the report from them locally - it works).