2025-04-23 18:01:11 +00:00
2024-07-22 21:37:31 +00:00
2026-03-30 16:35:24 +02:00
2024-07-22 21:37:09 +00:00
2024-07-22 21:37:09 +00:00
2026-03-30 16:33:30 +02:00
2023-01-08 04:53:03 +02:00
2025-04-23 18:01:11 +00:00
2025-04-24 06:44:11 +00:00
2025-04-24 06:44:11 +00:00
2026-03-30 16:31:40 +02:00
2023-10-16 16:52:34 +00:00

Library for creating Woodpecker CI plugins

Provides basic structure and helpers to load Woodpecker CI environment variables while also supporting reading Drone CI environment variables where available.

Adds logging support based on zerolog library and allows configurable HTTP client library.

Builtin settings

Settings Name Environment variable Default Description
log_level - info Sets log level (panic, fatal, error, warn, info, debug, trace)
skip_verify - false Skip verification of TLS certificate
SOCKS_PROXY none SOCKS5 proxy to use for connections
SOCKS_PROXY_OFF none Do not use SOCKS5 proxy

Optional: HTTP proxy support

HTTP proxy support is opt-in and must be explicitly enabled by the plugin author via EnableHTTPProxy: true in plugin.Options. When enabled, the following settings become available:

Settings Name Environment variable Default Description
http_proxy HTTP_PROXY none HTTP proxy URL for outgoing connections
https_proxy HTTPS_PROXY none HTTPS proxy URL for outgoing connections
no_proxy NO_PROXY none Comma-separated list of hosts to exclude from proxying

The settings are resolved in the following order of precedence:

  1. Plugin settingsPLUGIN_HTTP_PROXY, PLUGIN_HTTPS_PROXY, PLUGIN_NO_PROXY
  2. Lowercase env varshttp_proxy, https_proxy, no_proxy
  3. Uppercase env varsHTTP_PROXY, HTTPS_PROXY, NO_PROXY

Example Woodpecker CI pipeline configuration:

steps:
  - name: my-plugin
    image: my-plugin:latest
    settings:
      http_proxy: http://proxy.example.com:3128
      https_proxy: http://proxy.example.com:3128
      no_proxy: "localhost,internal.example.com"

Creating plugin

package main

import (
	"context"

	"codeberg.org/woodpecker-plugins/go-plugin"
	"github.com/rs/zerolog/log"
	"github.com/urfave/cli/v3"
)

type Settings struct {
	// TODO: Plugin settings
	SampleFlag string
}

type Plugin struct {
	*plugin.Plugin
	Settings *Settings
}

func (p *Plugin) Flags() []cli.Flag {
	return []cli.Flag{
		// TODO: Add flags
		&cli.StringFlag{
			Name:        "sample.flag",
			Usage:       "sample flag",
			Sources:     cli.EnvVars("PLUGIN_SAMPLE_FLAG"),
			Destination: &p.Settings.SampleFlag,
		},
	}
}

func (p *Plugin) Execute(ctx context.Context) error {
	// TODO: Implement execution
	log.Debug().Msg("executed")
	return nil
}

func main() {
	p := &Plugin{
		Settings: &Settings{},
	}

	p.Plugin = plugin.New(plugin.Options{
		Name:            "sample-plugin",
		Description:     "Sample plugin",
		Flags:           p.Flags(),
		Execute:         p.Execute,
		EnableHTTPProxy: true, // opt-in to HTTP proxy support
	})

	p.Run()
}
S
Description
No description provided
Readme Apache-2.0 319 KiB
Languages
Go 97%
Makefile 2%
Nix 1%