Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ package main

import (
"context"
"fmt"
"os"

"github.com/joho/godotenv"
"github.com/rs/zerolog/log"

"go.woodpecker-ci.org/woodpecker/v3/cmd/agent/core"
"go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/docker"
"go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/kubernetes"
"go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/local"
backend_types "go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/types"
"go.woodpecker-ci.org/woodpecker/v3/shared/dot_env"
"go.woodpecker-ci.org/woodpecker/v3/shared/utils"
)

Expand All @@ -37,10 +35,7 @@ var backends = []backend_types.Backend{
}

func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
dot_env.Load()

ctx := utils.WithContextSigtermCallback(context.Background(), func() {
log.Info().Msg("termination signal is received, shutting down agent")
Expand Down
8 changes: 2 additions & 6 deletions cmd/agent/man.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ package main

import (
"fmt"
"os"

"github.com/joho/godotenv"
docs "github.com/urfave/cli-docs/v3"

"go.woodpecker-ci.org/woodpecker/v3/cmd/agent/core"
"go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/docker"
"go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/kubernetes"
"go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/local"
backend_types "go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/types"
"go.woodpecker-ci.org/woodpecker/v3/shared/dot_env"
)

var backends = []backend_types.Backend{
Expand All @@ -37,10 +36,7 @@ var backends = []backend_types.Backend{
}

func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
dot_env.Load()

app := core.GenApp(backends)
md, err := docs.ToMan(app)
Expand Down
8 changes: 2 additions & 6 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@ package main

import (
"context"
"fmt"
"os"

"github.com/joho/godotenv"
"github.com/rs/zerolog/log"

"go.woodpecker-ci.org/woodpecker/v3/shared/dot_env"
"go.woodpecker-ci.org/woodpecker/v3/shared/utils"
)

func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
dot_env.Load()

ctx := utils.WithContextSigtermCallback(context.Background(), func() {
log.Info().Msg("termination signal is received, terminate cli")
Expand Down
8 changes: 2 additions & 6 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ package main

import (
"context"
"fmt"
"os"

"github.com/joho/godotenv"
"github.com/rs/zerolog/log"

_ "go.woodpecker-ci.org/woodpecker/v3/cmd/server/openapi"
"go.woodpecker-ci.org/woodpecker/v3/shared/dot_env"
"go.woodpecker-ci.org/woodpecker/v3/shared/utils"
)

func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
dot_env.Load()

ctx := utils.WithContextSigtermCallback(context.Background(), func() {
log.Info().Msg("termination signal is received, shutting down server")
Expand Down
8 changes: 2 additions & 6 deletions cmd/server/man.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ package main

import (
"fmt"
"os"

"github.com/joho/godotenv"
docs "github.com/urfave/cli-docs/v3"

_ "go.woodpecker-ci.org/woodpecker/v3/cmd/server/openapi"
"go.woodpecker-ci.org/woodpecker/v3/shared/dot_env"
)

func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
dot_env.Load()

app := genApp()
md, err := docs.ToMan(app)
Expand Down
3 changes: 2 additions & 1 deletion pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string)
// After the informer signals completion, kubelet may not have finalized
// containerStatuses yet (phase=Succeeded before state.terminated is set).
// Retry with backoff to allow kubelet to catch up.
pod, err := backoff.Retry(ctx,
pod, err := backoff.Retry(
ctx,
func() (*kube_core_v1.Pod, error) {
p, err := e.client.CoreV1().Pods(e.config.GetNamespace(step.OrgID)).Get(ctx, podName, kube_meta_v1.GetOptions{})
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions shared/dot_env/dot_env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2026 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dot_env

import (
"fmt"
"os"

"github.com/joho/godotenv"
)

const dotEnv = ".env"

func Load() {
if _, err := os.Stat(dotEnv); os.IsNotExist(err) {
return
}

if err := godotenv.Load(dotEnv); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load %q: %s", dotEnv, err)
os.Exit(1)
}
}