Skip to content

Commit b2243bd

Browse files
Merge pull request #3 from ctrlplanedev/zacharyb/init-agent
feat: Init Agent Intergation
2 parents 9b5a1ac + 9cbe278 commit b2243bd

File tree

76 files changed

+3160
-344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3160
-344
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @jenkinsci/ctrlplanexw-plugin-developers
1+
* @zacharyblasczyk @jsbroks

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
*.tar.gz
2020
*.rar
2121

22+
.idea/
23+
24+
2225
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2326
hs_err_pid*
2427
replay_pid*
2528

2629
target/
30+
work/

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "automatic"
3+
}

CONTRIBUTING.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing to the Ctrlplane Jenkins Plugin
2+
3+
Thank you for considering contributing to the Ctrlplane Jenkins Plugin!
4+
5+
We welcome pull requests! Please follow these steps:
6+
7+
1. **Fork the Repository:** Create your own fork of the [ctrlplanedev/jenkins-plugin](https://github.com/ctrlplanedev/jenkins-plugin) repository.
8+
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`).
9+
3. **Make Changes:** Implement your fix or feature.
10+
* Adhere to the existing code style. Run `mvn spotless:apply` to format your code, and `mvn verify` to check code style and run tests.
11+
* Add unit tests for new functionality or bug fixes, if applicable.
12+
4. **Test:** Build the plugin (`mvn clean package`) and test your changes in a local Jenkins instance if possible.
13+
5. **Commit:** Commit your changes with clear and concise commit messages.
14+
6. **Push:** Push your branch to your fork (`git push origin feature/my-new-feature`).
15+
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`.
16+
* Provide a clear title and description for your pull request, explaining the changes and referencing any related issues (e.g., "Fixes #123").
17+
18+
## Code Style
19+
20+
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.
21+
22+
## Questions?
23+
24+
If you have questions about contributing, feel free to open an issue.
25+
26+
Thank you for your contributions!

Jenkinsfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
https://github.com/jenkins-infra/pipeline-library/
44
*/
55
buildPlugin(
6-
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
7-
useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests
6+
forkCount: '1C',
7+
useContainerAgent: true,
88
configurations: [
99
[platform: 'linux', jdk: 21],
1010
[platform: 'windows', jdk: 17],
11-
])
11+
],
12+
)

README.md

+8-14
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,24 @@
22

33
## Introduction
44

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

79
## Getting started
810

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

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

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

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

2019
## Contributing
2120

22-
TODO review the default
23-
[CONTRIBUTING](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md)
24-
file and make sure it is appropriate for your plugin, if not then add your own
25-
one adapted from the base file
26-
2721
Refer to our [contribution guidelines](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md)
2822

2923
## LICENSE
3024

31-
Licensed under MIT, see [LICENSE](LICENSE.md)
25+
Licensed under MIT, see [LICENSE](LICENSE)

example.Jenkinsfile

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1+
import groovy.json.JsonOutput
2+
13
pipeline {
24
agent any
35

46
parameters {
5-
string(name: 'JOB_ID', defaultValue: '', description: 'Ctrlplane Job ID')
6-
string(name: 'API_URL', defaultValue: 'https://api.example.com', description: 'API Base URL (optional)')
7+
string(name: 'JOB_ID', defaultValue: '', description: 'Ctrlplane Job ID passed by the plugin')
78
}
89

910
stages {
10-
stage('Deploy') {
11+
stage('Fetch Ctrlplane Job Details') {
1112
steps {
1213
script {
1314
if (!params.JOB_ID) {
1415
error 'JOB_ID parameter is required'
1516
}
16-
17-
def ctrlplane = load 'src/utils/CtrlplaneClient.groovy'
18-
def job = ctrlplane.getJob(
19-
params.JOB_ID,
20-
params.API_URL,
21-
// params.API_KEY
22-
)
23-
24-
if (!job) {
25-
error "Failed to fetch data for job ${params.JOB_ID}"
26-
}
27-
28-
echo "Job status: ${job.id}"
17+
echo "Fetching details for Job ID: ${params.JOB_ID}"
18+
19+
def jobDetails = ctrlplaneGetJob jobId: params.JOB_ID
20+
21+
echo "-----------------------------------------"
22+
echo "Successfully fetched job details:"
23+
echo JsonOutput.prettyPrint(JsonOutput.toJson(jobDetails))
24+
echo "-----------------------------------------"
25+
26+
// Example: Access specific fields from the returned map
27+
// if(jobDetails.variables) {
28+
// echo "Specific Variable: ${jobDetails.variables.your_variable_name}"
29+
// }
30+
// if(jobDetails.metadata) {
31+
// echo "Metadata Value: ${jobDetails.metadata.your_metadata_key}"
32+
// }
33+
// if(jobDetails.job_config) {
34+
// echo "Job Config: ${jobDetails.job_config.jobUrl}"
35+
// }
2936
}
3037
}
3138
}

pom.xml

+33-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.jenkins-ci.plugins</groupId>
77
<artifactId>plugin</artifactId>
8-
<version>4.85</version>
8+
<version>5.9</version>
99
<relativePath />
1010
</parent>
1111

@@ -14,14 +14,27 @@
1414
<version>${revision}${changelist}</version>
1515
<packaging>hpi</packaging>
1616

17-
<name>TODO Plugin</name>
17+
<name>Ctrlplane Plugin</name>
1818
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
1919
<licenses>
2020
<license>
2121
<name>MIT License</name>
2222
<url>https://opensource.org/license/mit/</url>
2323
</license>
2424
</licenses>
25+
26+
<developers>
27+
<developer>
28+
<id>zacharyblasczyk</id>
29+
<name>Zachary Blasczyk</name>
30+
<email>[email protected]</email>
31+
</developer>
32+
<developer>
33+
<id>jsbrooks</id>
34+
<name>Justin Brooks</name>
35+
<email>[email protected]</email>
36+
</developer>
37+
</developers>
2538
<scm child.scm.connection.inherit.append.path="false" child.scm.developerConnection.inherit.append.path="false" child.scm.url.inherit.append.path="false">
2639
<connection>scm:git:https://github.com/${gitHubRepo}</connection>
2740
<developerConnection>scm:git:https://github.com/${gitHubRepo}</developerConnection>
@@ -32,49 +45,48 @@
3245
<properties>
3346
<revision>1.0</revision>
3447
<changelist>-SNAPSHOT</changelist>
35-
36-
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
37-
<jenkins.version>2.440.3</jenkins.version>
38-
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
39-
48+
<jenkins.baseline>2.492</jenkins.baseline>
49+
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
50+
<!-- <gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo> -->
51+
<gitHubRepo>ctrlplanedev/jenkins-agent-plugin</gitHubRepo>
4052
<spotless.check.skip>false</spotless.check.skip>
4153
</properties>
4254

4355
<dependencyManagement>
4456
<dependencies>
4557
<dependency>
46-
<!-- Pick up common dependencies for the selected LTS line: https://github.com/jenkinsci/bom#usage -->
4758
<groupId>io.jenkins.tools.bom</groupId>
48-
<artifactId>bom-2.440.x</artifactId>
49-
<version>3193.v330d8248d39e</version>
59+
<artifactId>bom-${jenkins.baseline}.x</artifactId>
60+
<version>4051.v78dce3ce8b_d6</version>
5061
<type>pom</type>
5162
<scope>import</scope>
5263
</dependency>
5364
</dependencies>
5465
</dependencyManagement>
66+
5567
<dependencies>
5668
<dependency>
57-
<groupId>org.jenkins-ci.plugins</groupId>
58-
<artifactId>structs</artifactId>
69+
<groupId>com.fasterxml.jackson.core</groupId>
70+
<artifactId>jackson-databind</artifactId>
71+
<version>2.15.3</version>
5972
</dependency>
6073
<dependency>
61-
<groupId>org.jenkins-ci.plugins.workflow</groupId>
62-
<artifactId>workflow-basic-steps</artifactId>
63-
<scope>test</scope>
74+
<groupId>org.jenkins-ci.plugins</groupId>
75+
<artifactId>structs</artifactId>
6476
</dependency>
6577
<dependency>
6678
<groupId>org.jenkins-ci.plugins.workflow</groupId>
67-
<artifactId>workflow-cps</artifactId>
68-
<scope>test</scope>
79+
<artifactId>workflow-step-api</artifactId>
6980
</dependency>
7081
<dependency>
71-
<groupId>org.jenkins-ci.plugins.workflow</groupId>
72-
<artifactId>workflow-durable-task-step</artifactId>
82+
<groupId>org.jenkins-ci.main</groupId>
83+
<artifactId>jenkins-test-harness</artifactId>
7384
<scope>test</scope>
7485
</dependency>
7586
<dependency>
76-
<groupId>org.jenkins-ci.plugins.workflow</groupId>
77-
<artifactId>workflow-job</artifactId>
87+
<groupId>org.mockito</groupId>
88+
<artifactId>mockito-core</artifactId>
89+
<version>4.11.0</version>
7890
<scope>test</scope>
7991
</dependency>
8092
</dependencies>

0 commit comments

Comments
 (0)