def __enter__(self): try: start_go_server(self.gocd_version) configurator = GoCdConfigurator(HostRestClient('localhost:8153')) pipeline = configurator \ .ensure_pipeline_group("P.Group") \ .ensure_replacement_of_pipeline("more-options") \ .set_timer("0 15 22 * * ?") \ .set_git_material( GitMaterial("[email protected]:springersbm/gomatic.git", material_name="some-material-name", polling=False)) \ .ensure_environment_variables( {'JAVA_HOME': '/opt/java/jdk-1.7'}) \ .ensure_parameters({'environment': 'qa'}) stage = pipeline.ensure_stage("earlyStage") job = stage.ensure_job("earlyWorm").ensure_artifacts( {BuildArtifact("scripts/*", "files"), BuildArtifact("target/universal/myapp*.zip", "artifacts"), TestArtifact("from", "to")}).set_runs_on_all_agents() job.add_task(ExecTask(['ls'])) configurator.save_updated_config(save_config_locally=True) return GoCdConfigurator(HostRestClient('localhost:8153')) except: # Swallow exception if __exit__ returns a True value if self.__exit__(*sys.exc_info()): pass else: raise
def __enter__(self): try: start_go_server(self.gocd_version, self.gocd_download_version_string) configurator = GoCdConfigurator(HostRestClient('localhost:8153')) pipeline = configurator \ .ensure_pipeline_group("P.Group") \ .ensure_replacement_of_pipeline("more-options") \ .set_timer("0 15 22 * * ?") \ .set_git_material(GitMaterial("https://github.com/SpringerSBM/gomatic.git", material_name="some-material-name", polling=False)) \ .ensure_environment_variables({'JAVA_HOME': '/opt/java/jdk-1.7'}) \ .ensure_parameters({'environment': 'qa'}) stage = pipeline.ensure_stage("earlyStage") job = stage.ensure_job("earlyWorm").ensure_artifacts({ Artifact.get_build_artifact("scripts/*", "files"), Artifact.get_build_artifact("target/universal/myapp*.zip", "artifacts"), Artifact.get_test_artifact("from", "to") }).set_runs_on_all_agents() job.add_task(ExecTask(['ls'])) configurator.save_updated_config(save_config_locally=True) return GoCdConfigurator(HostRestClient('localhost:8153')) except: # Swallow exception if __exit__ returns a True value if self.__exit__(*sys.exc_info()): pass else: raise
class ConfigureCommand(object): def __init__(self, args, hop_config): self.args = args self.hop_config = hop_config self.plans = {} self.configurator = GoCdConfigurator( SecureHostRestClient(host=args.host or hop_config.host, username=args.user or 'admin', password=args.password or hop_config.admin_password, ssl=False)) def execute(self): for app_name, app_config in _find_all_apps(self.args.context).items(): try: plan = self.get_plan(app_config['plan']) plan.execute(self.configurator, app_name, app_config) except KeyError: print("WARN: app '{}' does not define a plan".format(app_name)) except Exception as exception: print(exception) print("WARN: couldnt find plan with name '{0}' for app '{1}'". format(app_config['plan'], app_name)) self.configurator.save_updated_config() def get_plan(self, plan_name): plan = self.plans.get(plan_name, None) if not plan: plan = import_module('hop.plans.{}'.format(plan_name)) self.plans[plan_name] = plan return plan
def __init__(self, args, hop_config): self.args = args self.hop_config = hop_config self.plans = {} self.configurator = GoCdConfigurator( SecureHostRestClient(host=args.host or hop_config.host, username=args.user or 'admin', password=args.password or hop_config.admin_password, ssl=False))
def dummy_ensure_pipeline(script): """ Run ``script`` against a dummy GoCdConfigurator set to export the config-after.xml. """ configurator = GoCdConfigurator(empty_config()) with open('test-config.yml') as test_config_file: test_config = yaml.safe_load(test_config_file) config = TestConfigMerger(test_config) script = imp.load_source('pipeline_script', script) script.install_pipelines(configurator, config) configurator.save_updated_config(save_config_locally=True, dry_run=True)
def cli( # pylint: disable=missing-docstring save_config_locally, dry_run, variable_files, env_variable_files, env_deploy_variable_files, cmd_line_vars): config = utils.ConfigMerger(variable_files, env_variable_files, env_deploy_variable_files, cmd_line_vars) # Create the pipeline configurator = GoCdConfigurator( HostRestClient(config['gocd_url'], config['gocd_username'], config['gocd_password'], ssl=True)) return_val = install_pipelines(configurator, config) configurator.save_updated_config( save_config_locally=save_config_locally, dry_run=dry_run) return return_val
def execute(args, **kwargs): # pylint: disable=unused-argument hop_config = kwargs['hop_config'] configurator = GoCdConfigurator( SecureHostRestClient(host=args.host or hop_config.configure_url, username=args.user or 'admin', password=args.password or hop_config.admin_password, ssl=True, verify_ssl=False)) configure(configurator, apps=_find_all_apps(args.context))
#!/usr/bin/env python from gomatic import GoCdConfigurator, HostRestClient, ExecTask, GitMaterial configurator = GoCdConfigurator(HostRestClient("go-server:8153")) pipeline = configurator\ .ensure_pipeline_group("inception")\ .ensure_replacement_of_pipeline("inception")\ .set_git_material(GitMaterial("https://github.com/ivanmoore/inception.git", polling=False))\ .set_timer("0 0 * * * ?") # run on the hour, every hour inception_job = pipeline.ensure_stage("inception").ensure_job("inception") inception_job.ensure_task(ExecTask(["python", "inception.py"])) configurator.save_updated_config()