Posts

How to share single Maven local repo among multiple builds with Takari

Image
Recently we started using Kubernetes plugin in our Jenkins for spinning up agents on demand. Every time a build starts it creates a new pod and once it the build finishes the pod is destroyed. The agents are not reusable. We use maven as a build tool and we have some jobs that download 7-8 Gb of dependecies. Sometimes the builds took 1 hour - 1 hour and a half to download the dependencies and most of the time the builds failed due to timeout. We created a volume that was mapped with the maven local repo of the agents, but maven local repository is not safe for concurrent access and we had to find something else. Luckily we found a maven plugin called Takari . Takari enables safe concurrent use of the local repository.  In order to share local repo among multiple builds you have to add the followin code in your pipelines bevore running maven tasks: sh """ curl -O http://repo1.maven.org/maven2/io/takari/aether/takari-local-repository/0.10.4/takari-local-reposito

How to update YAML file with Ansible

Recently I had a task to update YAML file with ansible. I thought that there is already an Ansible module that does it, but I couldn't find any. Anyway it turned out that it is quite simple to do it with python. You just have to create a python file which you execute in Ansible. Here is the python file: import collections import io import sys import yaml filename = str(sys.argv[1]) snippet = yaml.load(sys.argv[2]) with io.open(filename, 'r', encoding='utf8') as f: yaml_dict = yaml.load(f) or {} def deep_update(source, overrides): for key, value in overrides.iteritems(): if isinstance(value, collections.Mapping) and value: returned = deep_update(source.get(key, {}), value) source[key] = returned else: source[key] = overrides[key] return source deep_update(yaml_dict, snippet) with io.open(filename, 'w', encoding='utf8') as f: yaml.dump(yaml_dict, f, default_flow_style=Fals