#Retrieving CI artifacts after a test failure

1 messages · Page 1 of 1 (latest)

signal falcon
#

Hi,

We are evaluating dagger, and we were wondering if there was any way to retrieve test reports files after a failure (non-zero exit code). For example (see code below), after running e2e browser tests, we would like to retrieve the junit (or xunit) report if the test failed.

Like docker build / buildx, if there is failure (non-zero exit code), the execution stops and no artifacts can be retrieved or exported. In a "classic" docker setup, we would build the image, then run the image with a mounted volume where the container can write the report to the host filesystem.

  • We tried mounting a volume with WithMountedDirectory("/output", src) but it seems to do much (no data in or out). Note that is on docker desktop on a Mac.
  • I could imagine we could workaround would be for the test to always exit with 0, export the report file and then fail based on the content of the report.
  • Would running the test as a service after the image has been built be a suitable workaround? Or would that break the caching?

Has anybody found a suitable workaround, or I just can't read the docs?

Thanks,

JM

#

Example code:

package main

import (
    "context"
    "fmt"
    "os"

    "dagger.io/dagger"
)

func main() {
    err := doCi()
    if err != nil {
        fmt.Println(err)
    }
}

func doCi() error {
    ctx := context.Background()

    client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
    if err != nil {
        return err
    }
    defer client.Close()

    src := client.Host().Directory(".")

    base := client.Container().From("alpine").
        WithMountedDirectory("/test", src).
        // Pretending to have a test failure
        WithExec([]string{"sh", "-c", "touch /test/result.xml && exit 1"})

    // Exporting to host so the reports can read by the CI
    export, err := base.File("/test/result.xml").Export(ctx, "result.xml")
    if err != nil {
        return err
    }
    fmt.Println(export)

    test, err := base.Stdout(ctx)
    if err != nil {
        return err
    }
    fmt.Println(test)

    return nil
}

signal falcon
#

Great! Thanks for the info. I was hoping for a more elegant solution, but that would do it.