Skip to content
Draft
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
6 changes: 6 additions & 0 deletions .buildkite/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

pipeline = Buildkite::Pipeline.new

is_fork_pr = Environment::BUILDKITE_PULL_REQUEST_REPO != "" && Environment::BUILDKITE_REPO == Environment::BUILDKITE_PULL_REQUEST_REPO
if is_fork_pr
puts pipeline.to_json
exit
end

plugins = [
{ "docker#v5.11.0": { image: "buildkite-sdk-tools:latest" } }
]
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ FROM ruby:latest AS base
RUN apt-get update && apt-get install -y \
curl \
git \
zip \
unzip \
&& rm -rf /var/lib/apt/lists/*

# Use Bash, and fail on any error.
Expand All @@ -26,5 +28,18 @@ RUN mise install go@latest && mise use --global go@latest
RUN pip install --no-cache-dir uv black
RUN npm install -g nx

# Install SDKMAN! for Java-based languages.
ENV SDKMAN_DIR="/usr/local/bin/sdkman"
RUN curl -s https://get.sdkman.io | bash

# Install Java and Groovy.
RUN bash -c "source $SDKMAN_DIR/bin/sdkman-init.sh && \
sdk install java 17.0.10-tem && \
sdk install groovy 4.0.26"

ENV JAVA_HOME="$SDKMAN_DIR/candidates/java/current"
ENV GROOVY_HOME="$SDKMAN_DIR/candidates/groovy/current"
ENV PATH="$JAVA_HOME/bin:$GROOVY_HOME/bin:$PATH"

# Override the default command (irb).
CMD ["true"]
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A multi-language SDK for [Buildkite](https://buildkite.com)! 🪁

Consumes the [Buildkite pipeline schema](https://github.com/buildkite/pipeline-schema) and generates and publishes packages for TypeScript, Python, Go, and Ruby.
Consumes the [Buildkite pipeline schema](https://github.com/buildkite/pipeline-schema) and generates and publishes packages for TypeScript, Python, Go, Ruby, and Groovy.

## Installing and using the SDKs

Expand Down Expand Up @@ -143,6 +143,31 @@ puts pipeline.to_json
puts pipeline.to_yaml
```

### Groovy

Install the package:

```bash
# TODO.
```

Use it in your program:

```groovy
import buildkite.Pipeline
import buildkite.StepTypes

def pipeline = new Pipeline()

pipeline.addStep([
label: "some-label",
command: "echo 'Hello, world!'"
])

print pipeline.toJSON()
print pipeline.toYAML()
```

## Development

### Prerequisites
Expand All @@ -160,6 +185,15 @@ brew bundle
mise install
```

For Groovy, you'll need to set up your Java environment -- we recommend [SDKMAN!](https://sdkman.io/)):

```bash
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 17.0.10-tem
sdk install groovy 4.0.26
```

If you hit any rough edges during development, please file an issue. Thanks!

### Useful commands
Expand Down
15 changes: 15 additions & 0 deletions apps/groovy/main.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import buildkite.Pipeline
import buildkite.StepTypes

def pipeline = new Pipeline()

pipeline.addStep([
label: "some-label",
command: "echo 'Hello, world!'",
])

def outputDir = new File("../../out/apps/groovy")
outputDir.mkdirs()

new File(outputDir, "pipeline.json").text = pipeline.toJSON()
new File(outputDir, "pipeline.yaml").text = pipeline.toYAML()
43 changes: 43 additions & 0 deletions apps/groovy/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "app-groovy",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "apps/groovy/src",
"targets": {
"install": {
"executor": "nx:run-commands",
"options": {
"commands": [],
"cwd": "apps/groovy",
"parallel": false
}
},
"clean": {
"executor": "nx:run-commands",
"options": {
"commands": [],
"cwd": "apps/groovy"
},
"cache": false
},
"run": {
"executor": "nx:run-commands",
"options": {
"commands": ["groovy -classpath ../../sdk/groovy main.groovy"],
"cwd": "apps/groovy",
"parallel": false
},
"dependsOn": ["install"]
},
"test": {
"executor": "nx:run-commands",
"outputs": [],
"options": {
"commands": [],
"cwd": "apps/groovy",
"parallel": false
},
"dependsOn": ["install"]
}
}
}
4 changes: 3 additions & 1 deletion project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"app-python:install",
"app-go:install",
"app-ruby:install",
"app-groovy:install",
"sdk-typescript:install",
"sdk-python:install",
"sdk-go:install",
Expand Down Expand Up @@ -118,7 +119,8 @@
"app-typescript:run",
"app-python:run",
"app-go:run",
"app-ruby:run"
"app-ruby:run",
"app-groovy:run"
]
},
"publish:all": {
Expand Down
205 changes: 205 additions & 0 deletions sdk/groovy/buildkite/EnvironmentVariable.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
package buildkite

/**
* Buildkite Environment Variables
* A Groovy enum equivalent to the TypeScript EnvironmentVariable
*/
enum EnvironmentVariable {
/**
* Always `true`
*/
BUILDKITE("BUILDKITE"),

/**
* The agent session token for the job. The variable is read by the agent `artifact` and `meta-data` commands.
*/
BUILDKITE_AGENT_ACCESS_TOKEN("BUILDKITE_AGENT_ACCESS_TOKEN"),

/**
* The value of the `debug` agent configuration option.
*/
BUILDKITE_AGENT_DEBUG("BUILDKITE_AGENT_DEBUG"),

/**
* The value of the `disconnect-after-job` agent configuration option.
*/
BUILDKITE_AGENT_DISCONNECT_AFTER_JOB("BUILDKITE_AGENT_DISCONNECT_AFTER_JOB"),

/**
* The value of the `disconnect-after-idle-timeout` agent configuration option.
*/
BUILDKITE_AGENT_DISCONNECT_AFTER_IDLE_TIMEOUT("BUILDKITE_AGENT_DISCONNECT_AFTER_IDLE_TIMEOUT"),

/**
* The value of the `endpoint` agent configuration option.
*/
BUILDKITE_AGENT_ENDPOINT("BUILDKITE_AGENT_ENDPOINT"),

/**
* A list of the experimental agent features that are currently enabled.
*/
BUILDKITE_AGENT_EXPERIMENT("BUILDKITE_AGENT_EXPERIMENT"),

/**
* The value of the `health-check-addr` agent configuration option.
*/
BUILDKITE_AGENT_HEALTH_CHECK_ADDR("BUILDKITE_AGENT_HEALTH_CHECK_ADDR"),

/**
* The UUID of the agent.
*/
BUILDKITE_AGENT_ID("BUILDKITE_AGENT_ID"),

/**
* The value of each agent tag.
*/
BUILDKITE_AGENT_META_DATA_("BUILDKITE_AGENT_META_DATA_"),

/**
* The name of the agent that ran the job.
*/
BUILDKITE_AGENT_NAME("BUILDKITE_AGENT_NAME"),

/**
* The process ID of the agent.
*/
BUILDKITE_AGENT_PID("BUILDKITE_AGENT_PID"),

/**
* The artifact paths to upload after the job, if any have been specified.
*/
BUILDKITE_ARTIFACT_PATHS("BUILDKITE_ARTIFACT_PATHS"),

/**
* The path where artifacts will be uploaded.
*/
BUILDKITE_ARTIFACT_UPLOAD_DESTINATION("BUILDKITE_ARTIFACT_UPLOAD_DESTINATION"),

/**
* The path to the directory containing the `buildkite-agent` binary.
*/
BUILDKITE_BIN_PATH("BUILDKITE_BIN_PATH"),

/**
* The branch being built.
*/
BUILDKITE_BRANCH("BUILDKITE_BRANCH"),

/**
* The path where the agent has checked out your code for this build.
*/
BUILDKITE_BUILD_CHECKOUT_PATH("BUILDKITE_BUILD_CHECKOUT_PATH"),

/**
* The name of the user who authored the commit being built.
*/
BUILDKITE_BUILD_AUTHOR("BUILDKITE_BUILD_AUTHOR"),

/**
* The notification email of the user who authored the commit being built.
*/
BUILDKITE_BUILD_AUTHOR_EMAIL("BUILDKITE_BUILD_AUTHOR_EMAIL"),

/**
* The name of the user who created the build.
*/
BUILDKITE_BUILD_CREATOR("BUILDKITE_BUILD_CREATOR"),

/**
* The notification email of the user who created the build.
*/
BUILDKITE_BUILD_CREATOR_EMAIL("BUILDKITE_BUILD_CREATOR_EMAIL"),

/**
* A colon separated list of non-private team slugs that the build creator belongs to.
*/
BUILDKITE_BUILD_CREATOR_TEAMS("BUILDKITE_BUILD_CREATOR_TEAMS"),

/**
* The UUID of the build.
*/
BUILDKITE_BUILD_ID("BUILDKITE_BUILD_ID"),

/**
* The build number.
*/
BUILDKITE_BUILD_NUMBER("BUILDKITE_BUILD_NUMBER"),

/**
* The value of the `build-path` agent configuration option.
*/
BUILDKITE_BUILD_PATH("BUILDKITE_BUILD_PATH"),

/**
* The url for this build on Buildkite.
*/
BUILDKITE_BUILD_URL("BUILDKITE_BUILD_URL"),

/**
* The value of the `cancel-grace-period` agent configuration option in seconds.
*/
BUILDKITE_CANCEL_GRACE_PERIOD("BUILDKITE_CANCEL_GRACE_PERIOD"),

/**
* The value of the `cancel-signal` agent configuration option.
*/
BUILDKITE_CANCEL_SIGNAL("BUILDKITE_CANCEL_SIGNAL"),

/**
* Whether the build should perform a clean checkout.
*/
BUILDKITE_CLEAN_CHECKOUT("BUILDKITE_CLEAN_CHECKOUT"),

/**
* The UUID value of the cluster.
*/
BUILDKITE_CLUSTER_ID("BUILDKITE_CLUSTER_ID"),

/**
* The command that will be run for the job.
*/
BUILDKITE_COMMAND("BUILDKITE_COMMAND"),

/**
* The opposite of the value of the `no-command-eval` agent configuration option.
*/
BUILDKITE_COMMAND_EVAL("BUILDKITE_COMMAND_EVAL"),

/**
* The exit code from the last command run in the command hook.
*/
BUILDKITE_COMMAND_EXIT_STATUS("BUILDKITE_COMMAND_EXIT_STATUS"),

/**
* The git commit object of the build.
*/
BUILDKITE_COMMIT("BUILDKITE_COMMIT"),

/**
* The path to the agent config file.
*/
BUILDKITE_CONFIG_PATH("BUILDKITE_CONFIG_PATH"),

/**
* The path to the file containing the job's environment variables.
*/
BUILDKITE_ENV_FILE("BUILDKITE_ENV_FILE"),

// More environment variables would be added here...

/**
* Always `true`.
*/
CI("CI")

private final String value

private EnvironmentVariable(String value) {
this.value = value
}

@Override
String toString() {
return value
}
}
Loading