diff --git a/pom.xml b/pom.xml
index 1f0b48fe3..12025440b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,6 +24,7 @@
0.71.0
1.12.14
+ 1462.v069a_b_57ff5c8
true
@@ -87,6 +88,19 @@
2.9.0
+
+ io.jenkins
+ configuration-as-code
+ ${configuration-as-code.version}
+ test
+
+
+ io.jenkins.configuration-as-code
+ test-harness
+ ${configuration-as-code.version}
+ test
+
+
org.mockito
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration.java b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration.java
index d9aaa2437..7675ccc5f 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration.java
@@ -118,6 +118,7 @@ public class DatadogGlobalConfiguration extends GlobalConfiguration {
private static final String GLOBAL_JOB_TAGS_PROPERTY = "DATADOG_JENKINS_PLUGIN_GLOBAL_JOB_TAGS";
private static final String EMIT_SECURITY_EVENTS_PROPERTY = "DATADOG_JENKINS_PLUGIN_EMIT_SECURITY_EVENTS";
private static final String EMIT_SYSTEM_EVENTS_PROPERTY = "DATADOG_JENKINS_PLUGIN_EMIT_SYSTEM_EVENTS";
+ private static final String EMIT_CONFIG_CHANGE_EVENTS_PROPERTY = "DATADOG_JENKINS_PLUGIN_EMIT_CONFIG_CHANGE_EVENTS";
private static final String INCLUDE_EVENTS_PROPERTY = "DATADOG_JENKINS_PLUGIN_INCLUDE_EVENTS";
private static final String EXCLUDE_EVENTS_PROPERTY = "DATADOG_JENKINS_PLUGIN_EXCLUDE_EVENTS";
private static final String COLLECT_BUILD_LOGS_PROPERTY = "DATADOG_JENKINS_PLUGIN_COLLECT_BUILD_LOGS";
@@ -141,6 +142,7 @@ public class DatadogGlobalConfiguration extends GlobalConfiguration {
private static final Integer DEFAULT_TARGET_LOG_COLLECTION_PORT_VALUE = null;
private static final boolean DEFAULT_EMIT_SECURITY_EVENTS_VALUE = true;
private static final boolean DEFAULT_EMIT_SYSTEM_EVENTS_VALUE = true;
+ private static final boolean DEFAULT_EMIT_CONFIG_CHANGE_EVENTS_VALUE = false;
private static final boolean DEFAULT_COLLECT_BUILD_LOGS_VALUE = false;
private static final boolean DEFAULT_COLLECT_BUILD_TRACES_VALUE = false;
private static final boolean DEFAULT_RETRY_LOGS_VALUE = true;
@@ -170,6 +172,7 @@ public class DatadogGlobalConfiguration extends GlobalConfiguration {
private String excludeEvents = null;
private boolean emitSecurityEvents = DEFAULT_EMIT_SECURITY_EVENTS_VALUE;
private boolean emitSystemEvents = DEFAULT_EMIT_SYSTEM_EVENTS_VALUE;
+ private boolean emitConfigChangeEvents = DEFAULT_EMIT_CONFIG_CHANGE_EVENTS_VALUE;
private boolean collectBuildLogs = DEFAULT_COLLECT_BUILD_LOGS_VALUE;
private boolean collectBuildTraces = DEFAULT_COLLECT_BUILD_TRACES_VALUE;
private boolean retryLogs = DEFAULT_RETRY_LOGS_VALUE;
@@ -266,6 +269,11 @@ public void loadEnvVariables() {
this.globalTagFile = globalTagFileEnvVar;
}
+ String emitConfigChangeEventsEnvVar = System.getenv(EMIT_CONFIG_CHANGE_EVENTS_PROPERTY);
+ if(StringUtils.isNotBlank(emitConfigChangeEventsEnvVar)){
+ this.emitConfigChangeEvents = Boolean.valueOf(emitConfigChangeEventsEnvVar);
+ }
+
String globalTagsEnvVar = System.getenv(GLOBAL_TAGS_PROPERTY);
if(StringUtils.isNotBlank(globalTagsEnvVar)){
this.globalTags = globalTagsEnvVar;
@@ -1203,6 +1211,23 @@ public void setIncluded(final String jobs) {
this.whitelist = jobs;
}
+ /**
+ * @return - A {@link Boolean} indicating if the user has configured Datadog to emit Config Change events.
+ */
+ public boolean isEmitConfigChangeEvents() {
+ return emitConfigChangeEvents;
+ }
+
+ /**
+ * Used for CasC
+ * accepting a comma-separated string of events.
+ *
+ * @param emitConfigChangeEvents - The checkbox status (checked/unchecked)
+ */
+ @DataBoundSetter
+ public void setEmitConfigChangeEvents(boolean emitConfigChangeEvents) {
+ this.emitConfigChangeEvents = emitConfigChangeEvents;
+ }
/**
* Gets the globalTagFile set in the job configuration.
*
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java
index 1661abeff..f44233418 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java
@@ -3,7 +3,9 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
+
import org.jvnet.hudson.test.JenkinsRule;
import hudson.util.Secret;
@@ -14,6 +16,10 @@
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.CredentialsStore;
import com.cloudbees.plugins.credentials.domains.Domain;
+
+import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
+import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
+
import java.io.IOException;
public class DatadogGlobalConfigurationTest {
@@ -21,6 +27,15 @@ public class DatadogGlobalConfigurationTest {
@ClassRule
public static JenkinsRule jenkinsRule = new JenkinsRule();
+ @Rule public JenkinsConfiguredWithCodeRule r = new JenkinsConfiguredWithCodeRule();
+
+ @Test
+ @ConfiguredWithCode("test-config.yml")
+ public void TestConfigurationAsCodeCompatibility() throws Exception {
+ DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
+ Assert.assertTrue(cfg.isEmitConfigChangeEvents());
+ }
+
@Test
public void testCanGetCredentialFromId() throws IOException {
CredentialsStore credentialsStore = CredentialsProvider.lookupStores(jenkinsRule).iterator().next();
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config.yml b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config.yml
new file mode 100644
index 000000000..d7f6d45e7
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config.yml
@@ -0,0 +1,8 @@
+jenkins:
+ systemMessage: "Example of configuring datadog in Jenkins"
+
+unclassified:
+ datadogGlobalConfiguration:
+ reportWith: 'http'
+ targetApiKey: 'test'
+ emitConfigChangeEvents: true