1

I'm migrating from GitLab CI to Woodpecker CI. The current pipeline is defined as:

default:
  cache:
    key: $CI_COMMIT_REF_SLUG
    paths:
      - $CI_PROJECT_DIR/.m2/repository/
  image: docker.io/library/eclipse-temurin:8-jdk-focal

stages:
  - compile

variables:
  MAVEN_CONFIG: --batch-mode --no-transfer-progress
  MAVEN_OPTS: -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository/

compile:
  stage: compile
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_MERGE_REQUEST_ID
  script:
    - ./mvnw compile $MAVEN_EXTRA_OPTS
  variables:
    MAVEN_EXTRA_OPTS: -DskipTests=true

I'm trying to find a way to declare MAVEN_CONFIG and MAVEN_OPTS in the same way they are exposed (read: globally for all steps) in GitLab CI, but I so far I haven't found a solution. I'm basically declaring them all over again in subsequent steps.

Is this functionality available and I missed it, or isn't yet implemented?

x80486
  • 6,627
  • 5
  • 52
  • 111

1 Answers1

1

You need to create a .woodpecker.yml file defining a pipeline with steps. See, Woodpecker CI: Intro.

# .woodpecker.yml
pipeline:
  build:
    image: debian
    commands:
      - echo "This is the build step"
  a-test-step:
    image: debian
    commands:
      - echo "Testing.."

To set environment variables, use the environment key. See, Woodpecker CI: Environment Variables.

pipeline:
  build:
    image: golang
    environment:
      # set environment variables
      - CGO=0
      - GOOS=linux
      - GOARCH=amd64
    commands:
      # expand/resolve environment variables by exporting
      - export PATH=$PATH:/go
      - go build
      - go test

Environment variables can be set globally for all builds via the WOODPECKER_ENVIRONMENT variable. See, Woodpecker CI: Global Env Vars.

You should be able to share commands between steps with yaml anchors and aliases, as in this example.

.set-maven-env-vars: &set-maven-env-vars
  - export MAVEN_CONFIG="--batch-mode --no-transfer-progress"
  - export MAVEN_OPTS="-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository/"

pipeline:
  build:
    image: golang
    commands:
      - *set-maven-env-vars
      - go build
      - go test
Richard
  • 2,226
  • 2
  • 19
  • 35
  • I don't have access to the instance, but regardless, I was leaning towards the solution about "having global variables within the pipeline". On GitHub they proposed to use aliases, but somehow I think having a dedicated key for this is better. So far, looks like it's not possible to declare them in the same way one would do in `GitLab CI`. – x80486 May 25 '22 at 12:35
  • 1
    You're right. You can't set env vars globally in a `.woodpecker.yml` like you can in a `.gitlab.yml`. Let me know if that last example works for you or not. – Richard May 25 '22 at 14:35
  • What does the dot in `.set-maven-env-vars` mean? How does Woodpecker interpret this code fragment before `pipeline`? – Joerg Oct 16 '22 at 20:04
  • https://stackoverflow.com/questions/24090177/how-to-merge-yaml-arrays/57209078#57209078 – Richard Oct 17 '22 at 21:04