This is a strange one. I am not sure why this works this way.
this works
package main
import (
"context"
"fmt"
"os"
"time"
"dagger.io/dagger"
)
func main() {
var test *dagger.Container
ctx := context.Background()
c, _ := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
mycontainer := c.Container().From("golang:1.20-alpine")
if true {
test = mycontainer.Pipeline("my pipeline").
WithEnvVariable("cb", time.Now().String()).
WithExec([]string{"echo", "HELLO_WORLD"})
} else {
test = mycontainer.Pipeline("my pipeline 2")
}
// test.
// WithEnvVariable("cb", time.Now().String()).
// WithExec([]string{"echo", "HELLO_WORLD"})
fmt.Println(test.Stdout(ctx))
}
this doesnt
package main
import (
"context"
"fmt"
"os"
"time"
"dagger.io/dagger"
)
func main() {
var test *dagger.Container
ctx := context.Background()
c, _ := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
mycontainer := c.Container().From("golang:1.20-alpine")
if true {
test = mycontainer.Pipeline("my pipeline")
// WithEnvVariable("cb", time.Now().String()).
// WithExec([]string{"echo", "HELLO_WORLD"})
} else {
test = mycontainer.Pipeline("my pipeline 2")
}
test.
WithEnvVariable("cb", time.Now().String()).
WithExec([]string{"echo", "HELLO_WORLD"})
fmt.Println(test.Stdout(ctx))
}
I am fairly new to Go so I'm probably doing something dumb. But I can't figure it out. Is there a way to write this so I can add additional stages to the container outside of the if block?