Skip to content

Instantly share code, notes, and snippets.

@tfheen
Created March 26, 2014 17:44
Show Gist options
  • Select an option

  • Save tfheen/9789098 to your computer and use it in GitHub Desktop.

Select an option

Save tfheen/9789098 to your computer and use it in GitHub Desktop.
diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py
index b222f75..c480477 100644
--- a/jenkins_jobs/builder.py
+++ b/jenkins_jobs/builder.py
@@ -32,7 +32,7 @@ import fnmatch
from jenkins_jobs.errors import JenkinsJobsException
logger = logging.getLogger(__name__)
-MAGIC_MANAGE_STRING = "<!-- Managed by Jenkins Job Builder -->"
+MAGIC_MANAGE_STRING = "<!-- Managed by Jenkins Job Builder: %s -->"
# Python <= 2.7.3's minidom toprettyxml produces broken output by adding
@@ -116,6 +116,10 @@ class YamlParser(object):
self.registry = ModuleRegistry(config)
self.data = {}
self.jobs = []
+ if config:
+ self.job_tag = config.get("jenkins", "job_tag")
+ else:
+ self.job_tag = None
def parse(self, fn):
data = yaml.load(open(fn))
@@ -279,8 +283,9 @@ class YamlParser(object):
def getXMLForJob(self, data):
kind = data.get('project-type', 'freestyle')
- data["description"] = (data.get("description", "") +
- self.get_managed_string()).lstrip()
+ if self.get_managed_string() is not None:
+ data["description"] = (data.get("description", "") +
+ self.get_managed_string()).lstrip()
for ep in pkg_resources.iter_entry_points(
group='jenkins_jobs.projects', name=kind):
Mod = ep.load()
@@ -299,7 +304,9 @@ class YamlParser(object):
def get_managed_string(self):
# The \n\n is not hard coded, because they get stripped if the
# project does not otherwise have a description.
- return "\n\n" + MAGIC_MANAGE_STRING
+ if self.job_tag is not None:
+ return "\n\n" + (MAGIC_MANAGE_STRING % self.job_tag)
+ return None
class ModuleRegistry(object):
diff --git a/jenkins_jobs/cmd.py b/jenkins_jobs/cmd.py
index 761dff1..10c1af7 100755
--- a/jenkins_jobs/cmd.py
+++ b/jenkins_jobs/cmd.py
@@ -79,7 +79,7 @@ def main():
if os.path.isfile(localconf):
conf = localconf
- config = ConfigParser.ConfigParser()
+ config = ConfigParser.ConfigParser({ "job_tag": "JJB" })
if os.path.isfile(conf):
logger.debug("Reading config from {0}".format(conf))
conffp = open(conf, 'r')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment