Skip to content

feat: Init Agent Intergation #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @jenkinsci/ctrlplanexw-plugin-developers
* @zacharyblasczyk @jsbroks
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
*.tar.gz
*.rar

.idea/


# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

target/
work/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing to the Ctrlplane Jenkins Plugin

Thank you for considering contributing to the Ctrlplane Jenkins Plugin!

We welcome pull requests! Please follow these steps:

1. **Fork the Repository:** Create your own fork of the [ctrlplanedev/jenkins-plugin](https://github.com/ctrlplanedev/jenkins-plugin) repository.
2. **Create a Branch:** Create a new branch in your fork for your changes (e.g., `git checkout -b feature/my-new-feature` or `git checkout -b fix/bug-description`).
3. **Make Changes:** Implement your fix or feature.
* Adhere to the existing code style. Consider using `mvn spotless:apply verify` to format your code.
* Add unit tests for new functionality or bug fixes if applicable.
4. **Test:** Build the plugin (`mvn clean package`) and test your changes in a local Jenkins instance if possible.
5. **Commit:** Commit your changes with clear and concise commit messages.
6. **Push:** Push your branch to your fork (`git push origin feature/my-new-feature`).
7. **Open a Pull Request:** Go to the original repository and open a pull request from your branch to the `main` branch of `ctrlplanedev/jenkins-plugin`.
* Provide a clear title and description for your pull request, explaining the changes and referencing any related issues (e.g., "Fixes #123").

## Code Style

This project uses [Spotless Maven Plugin](https://github.com/diffplug/spotless/tree/main/plugin-maven) to enforce code style. Please run `mvn spotless:apply` before committing to format your code automatically.

## Questions?

If you have questions about contributing, feel free to open an issue.

Thank you for your contributions!
7 changes: 4 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
https://github.com/jenkins-infra/pipeline-library/
*/
buildPlugin(
forkCount: '1C', // run this number of tests in parallel for faster feedback. If the number terminates with a 'C', the value will be multiplied by the number of available CPU cores
useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests
forkCount: '1C',
useContainerAgent: true,
configurations: [
[platform: 'linux', jdk: 21],
[platform: 'windows', jdk: 17],
])
],
)
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

## Introduction

TODO Describe what your plugin does here
This plugin integrates Jenkins with Ctrlplane by acting as a Job Agent.
It allows Ctrlplane to trigger specific Jenkins pipeline jobs as part of a Deployment workflow.
The plugin polls Ctrlplane for pending jobs assigned to it and injects job context (like the Ctrlplane Job ID) into the triggered Jenkins pipeline.

## Getting started

TODO Tell users how to configure your plugin here, include screenshots, pipeline
examples and configuration-as-code examples.
For detailed installation, configuration, and usage instructions, please refer to the official documentation:

## Issues
[**Ctrlplane Jenkins Integration Documentation**](https://docs.ctrlplane.dev/integrations/saas/jenkins)

TODO Decide where you're going to host your issues, the default is Jenkins JIRA,
but you can also enable GitHub issues, If you use GitHub issues there's no need
for this section; else add the following line:
## Issues

Report issues and enhancements in the [Jenkins issue tracker](https://issues.jenkins.io/).
Report issues and enhancements on the [GitHub Issues page](https://github.com/ctrlplanedev/jenkins-plugin/issues).

## Contributing

TODO review the default
[CONTRIBUTING](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md)
file and make sure it is appropriate for your plugin, if not then add your own
one adapted from the base file

Refer to our [contribution guidelines](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md)

## LICENSE

Licensed under MIT, see [LICENSE](LICENSE.md)
Licensed under MIT, see [LICENSE](LICENSE)
39 changes: 23 additions & 16 deletions example.Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import groovy.json.JsonOutput

pipeline {
agent any

parameters {
string(name: 'JOB_ID', defaultValue: '', description: 'Ctrlplane Job ID')
string(name: 'API_URL', defaultValue: 'https://api.example.com', description: 'API Base URL (optional)')
string(name: 'JOB_ID', defaultValue: '', description: 'Ctrlplane Job ID passed by the plugin')
}

stages {
stage('Deploy') {
stage('Fetch Ctrlplane Job Details') {
steps {
script {
if (!params.JOB_ID) {
error 'JOB_ID parameter is required'
}

def ctrlplane = load 'src/utils/CtrlplaneClient.groovy'
def job = ctrlplane.getJob(
params.JOB_ID,
params.API_URL,
// params.API_KEY
)

if (!job) {
error "Failed to fetch data for job ${params.JOB_ID}"
}

echo "Job status: ${job.id}"
echo "Fetching details for Job ID: ${params.JOB_ID}"

def jobDetails = ctrlplaneGetJob jobId: params.JOB_ID

echo "-----------------------------------------"
echo "Successfully fetched job details:"
echo JsonOutput.prettyPrint(JsonOutput.toJson(jobDetails))
echo "-----------------------------------------"

// Example: Access specific fields from the returned map
// if(jobDetails.variables) {
// echo "Specific Variable: ${jobDetails.variables.your_variable_name}"
// }
// if(jobDetails.metadata) {
// echo "Metadata Value: ${jobDetails.metadata.your_metadata_key}"
// }
// if(jobDetails.job_config) {
// echo "Job Config: ${jobDetails.job_config.jobUrl}"
// }
}
}
}
Expand Down
54 changes: 33 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.85</version>
<version>5.9</version>
<relativePath />
</parent>

Expand All @@ -14,14 +14,27 @@
<version>${revision}${changelist}</version>
<packaging>hpi</packaging>

<name>TODO Plugin</name>
<name>Ctrlplane Plugin</name>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/license/mit/</url>
</license>
</licenses>

<developers>
<developer>
<id>zacharyblasczyk</id>
<name>Zachary Blasczyk</name>
<email>zachary@ctrlplane.dev</email>
</developer>
<developer>
<id>jsbrooks</id>
<name>Justin Brooks</name>
<email>justin@ctrlplane.dev</email>
</developer>
</developers>
<scm child.scm.connection.inherit.append.path="false" child.scm.developerConnection.inherit.append.path="false" child.scm.url.inherit.append.path="false">
<connection>scm:git:https://github.com/${gitHubRepo}</connection>
<developerConnection>scm:git:https://github.com/${gitHubRepo}</developerConnection>
Expand All @@ -32,49 +45,48 @@
<properties>
<revision>1.0</revision>
<changelist>-SNAPSHOT</changelist>

<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.version>2.440.3</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>

<jenkins.baseline>2.492</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<!-- <gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo> -->
<gitHubRepo>ctrlplanedev/jenkins-agent-plugin</gitHubRepo>
<spotless.check.skip>false</spotless.check.skip>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<!-- Pick up common dependencies for the selected LTS line: https://github.com/jenkinsci/bom#usage -->
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.440.x</artifactId>
<version>3193.v330d8248d39e</version>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>4051.v78dce3ce8b_d6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<scope>test</scope>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<scope>test</scope>
<artifactId>workflow-step-api</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Loading