示例#1
0
def Build(messages,
          async_,
          build_config,
          hide_logs=False,
          build_region=cloudbuild_util.DEFAULT_REGION):
    """Starts the build."""
    log.debug('submitting build: ' + repr(build_config))
    client = cloudbuild_util.GetClientInstance()

    parent_resource = resources.REGISTRY.Create(
        collection='cloudbuild.projects.locations',
        projectsId=properties.VALUES.core.project.GetOrFail(),
        locationsId=build_region)

    op = client.projects_locations_builds.Create(
        messages.CloudbuildProjectsLocationsBuildsCreateRequest(
            parent=parent_resource.RelativeName(), build=build_config))

    json = encoding.MessageToJson(op.metadata)
    build = encoding.JsonToMessage(messages.BuildOperationMetadata, json).build

    # Need to set the default version to 'v1'
    build_ref = resources.REGISTRY.Parse(
        None,
        collection='cloudbuild.projects.locations.builds',
        api_version='v1',
        params={
            'projectsId': build.projectId,
            'locationsId': build_region,
            'buildsId': build.id,
        })

    if not hide_logs:
        log.CreatedResource(build_ref)
        if build.logUrl:
            log.status.Print('Logs are available at [{log_url}].'.format(
                log_url=build.logUrl))
        else:
            log.status.Print('Logs are available in the Cloud Console.')

    # If the command is run --async, we just print out a reference to the build.
    if async_:
        return build, op

    mash_handler = execution.MashHandler(
        execution.GetCancelBuildHandler(client, messages, build_ref))

    # Otherwise, logs are streamed from GCS.
    with execution_utils.CtrlCSection(mash_handler):
        build = cb_logs.CloudBuildClient(client, messages).Stream(build_ref)

    if build.status == messages.Build.StatusValueValuesEnum.TIMEOUT:
        log.status.Print(
            'Your build timed out. Use the [--timeout=DURATION] flag to change '
            'the timeout threshold.')

    if build.status != messages.Build.StatusValueValuesEnum.SUCCESS:
        raise FailedBuildException(build)

    return build, op
示例#2
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        parent = properties.VALUES.core.project.Get(required=True)
        # Get the parent project ref
        parent_resource = resources.REGISTRY.Create(
            collection='cloudbuild.projects', projectId=parent)

        # Send the List request
        ghe_list = client.projects_githubEnterpriseConfigs.List(
            messages.CloudbuildProjectsGithubEnterpriseConfigsListRequest(
                parent=parent_resource.RelativeName())).configs

        return ghe_list
示例#3
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

    client = cloudbuild_util.GetClientInstance()
    messages = cloudbuild_util.GetMessagesModule()

    parent = properties.VALUES.core.project.Get(required=True)
    # Get the parent project ref
    parent_resource = resources.REGISTRY.Create(
        collection='cloudbuild.projects.locations',
        projectsId=parent,
        # Use default region global until Proctor is fully regionalized.
        locationsId=cloudbuild_util.DEFAULT_REGION)

    # Send the List request
    bbs_list = client.projects_locations_bitbucketServerConfigs.List(
        messages.CloudbuildProjectsLocationsBitbucketServerConfigsListRequest(
            parent=parent_resource.RelativeName())).bitbucketServerConfigs

    return bbs_list
示例#4
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        parent = properties.VALUES.core.project.Get(required=True)
        config_id = args.CONFIG
        # Get the bitbucket server config ref
        bbs_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.locations.bitbucketServerConfigs',
            api_version='v1',
            params={
                'projectsId': parent,
                # Use default region global until Proctor is fully regionalized.
                'locationsId': cloudbuild_util.DEFAULT_REGION,
                'bitbucketServerConfigsId': config_id,
            })

        # Send the Get request
        bbs = client.projects_locations_bitbucketServerConfigs.Get(
            messages.
            CloudbuildProjectsLocationsBitbucketServerConfigsGetRequest(
                name=bbs_resource.RelativeName()))
        return bbs
 def Run(self, args):
     """This is what gets called when the user runs this command."""
     region_ref = args.CONCEPTS.region.Parse()
     region = region_ref.AsDict()['locationsId']
     project = properties.VALUES.core.project.Get(required=True)
     run_id = args.RUN_ID
     if args.type == 'build':
         client = v1_client_util.GetClientInstance()
         messages = v1_client_util.GetMessagesModule()
         build_ref = resources.REGISTRY.Parse(
             run_id,
             params={
                 'projectsId': project,
                 'locationsId': region,
                 'buildsId': run_id,
             },
             collection='cloudbuild.projects.locations.builds')
         logger = v1_logs.CloudBuildClient(client, messages, True)
         if args.stream:
             logger.Stream(build_ref)
             return
         logger.PrintLog(build_ref)
         return
     else:
         logger = v2_logs.CloudBuildLogClient()
         if args.stream:
             logger.Stream(project, region, run_id, args.type)
             return
         logger.PrintLog(project, region, run_id, args.type)
         return
    def Run(self, args):
        """Lists the build triggers in a project.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()

        project = properties.VALUES.core.project.Get(required=True)
        location = args.region or cloudbuild_util.DEFAULT_REGION

        parent = resources.REGISTRY.Create(
            collection='cloudbuild.projects.locations',
            projectsId=project,
            locationsId=location).RelativeName()

        return client.projects_locations_triggers.List(
            client.MESSAGES_MODULE.
            CloudbuildProjectsLocationsTriggersListRequest(
                parent=parent)).triggers
示例#7
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        build_region = args.region or cloudbuild_util.DEFAULT_REGION

        client = cloudbuild_util.GetClientInstance()

        build_ref = resources.REGISTRY.Parse(
            args.build,
            params={
                'projectsId': properties.VALUES.core.project.GetOrFail,
                'locationsId': build_region,
                'buildsId': args.build,
            },
            collection='cloudbuild.projects.locations.builds')
        return client.projects_locations_builds.Get(
            client.MESSAGES_MODULE.CloudbuildProjectsLocationsBuildsGetRequest(
                name=build_ref.RelativeName()))
示例#8
0
  def Run(self, args):
    """Describes a build trigger..

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

    client = cloudbuild_util.GetClientInstance()

    project = properties.VALUES.core.project.Get(required=True)
    location = args.region or cloudbuild_util.DEFAULT_REGION
    trigger = args.TRIGGER

    name = resources.REGISTRY.Parse(
        trigger,
        params={
            'projectsId': project,
            'locationsId': location,
            'triggersId': trigger,
        },
        collection='cloudbuild.projects.locations.triggers').RelativeName()

    return client.projects_locations_triggers.Get(
        client.MESSAGES_MODULE.CloudbuildProjectsLocationsTriggersGetRequest(
            name=name, triggerId=trigger))
示例#9
0
    def Run(self, args):
        """Imports a build trigger.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        project = properties.VALUES.core.project.Get(required=True)
        location = args.region or cloudbuild_util.DEFAULT_REGION
        triggers = cloudbuild_util.LoadMessagesFromPath(
            args.source,
            messages.BuildTrigger,
            'BuildTrigger',
            skip_camel_case=['substitutions'])

        return [
            self._CreateOrUpdateTrigger(client, messages, project, location,
                                        trigger) for trigger in triggers
        ]
示例#10
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        ongoing_filter = None
        if args.ongoing:
            ongoing_filter = 'status="WORKING" OR status="QUEUED"'

        return list_pager.YieldFromList(
            client.projects_builds,
            messages.CloudbuildProjectsBuildsListRequest(
                pageSize=args.page_size,
                projectId=properties.VALUES.core.project.Get(),
                filter=ongoing_filter),
            field='builds',
            batch_size=args.page_size,
            batch_size_attribute='pageSize')
示例#11
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        build_region = args.region or cloudbuild_util.DEFAULT_REGION

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        build_ref = resources.REGISTRY.Parse(
            args.build,
            params={
                'projectsId': properties.VALUES.core.project.GetOrFail,
                'locationsId': build_region,
            },
            collection='cloudbuild.projects.locations.builds')

        logger = cb_logs.CloudBuildClient(client, messages, self._support_gcl)
        if args.stream:
            if not self._support_gcl:
                log.status.Print(
                    '\ngcloud builds log --stream only displays logs from Cloud'
                    ' Storage. To view logs from Cloud Logging, run:\ngcloud beta'
                    ' builds log --stream\n')
            logger.Stream(build_ref)
            return

        # Just print out what's available now.
        logger.PrintLog(build_ref)
示例#12
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

    client = cloudbuild_util.GetClientInstance()
    messages = cloudbuild_util.GetMessagesModule()

    trigger = self.ParseTriggerFromFlags(args)

    # Send the Create request
    project = properties.VALUES.core.project.Get(required=True)
    created_trigger = client.projects_triggers.Create(
        messages.CloudbuildProjectsTriggersCreateRequest(
            buildTrigger=trigger, projectId=project))

    trigger_resource = resources.REGISTRY.Parse(
        None,
        collection='cloudbuild.projects.triggers',
        api_version='v1',
        params={
            'projectId': project,
            'triggerId': created_trigger.id,
        })
    log.CreatedResource(trigger_resource)

    return created_trigger
示例#13
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        cancelled = []
        for build in args.builds:
            build_ref = resources.REGISTRY.Parse(
                build,
                params={'projectId': properties.VALUES.core.project.GetOrFail},
                collection='cloudbuild.projects.builds')
            cancelled_build = client.projects_builds.Cancel(
                messages.CloudbuildProjectsBuildsCancelRequest(
                    projectId=build_ref.projectId, id=build_ref.id))
            log.status.write('Cancelled [{r}].\n'.format(r=str(build_ref)))
            cancelled.append(cancelled_build)
        return cancelled
示例#14
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        args.filter, server_filter = filter_rewrite.Backend(
            args.ongoing).Rewrite(args.filter)

        return list_pager.YieldFromList(
            client.projects_builds,
            messages.CloudbuildProjectsBuildsListRequest(
                pageSize=args.page_size,
                projectId=properties.VALUES.core.project.GetOrFail(),
                filter=server_filter),
            field='builds',
            batch_size=args.page_size,
            limit=args.limit,
            batch_size_attribute='pageSize')
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        parent = properties.VALUES.core.project.Get(required=True)
        config_id = args.CONFIG
        # Get the GitLab Enterprise config ref
        gitlab_config_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.locations.gitLabConfigs',
            api_version='v1',
            params={
                'projectsId': parent,
                'locationsId': args.region,
                'gitLabConfigsId': config_id,
            })

        # Send the Get request
        gitlab_config = client.projects_locations_gitLabConfigs.Get(
            messages.CloudbuildProjectsLocationsGitLabConfigsGetRequest(
                name=gitlab_config_resource.RelativeName()))
        return gitlab_config
示例#16
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()
        registry = self.context['registry']

        build_ref = registry.Parse(
            args.build,
            params={
                'projectId': properties.VALUES.core.project.GetOrFail,
            },
            collection='cloudbuild.projects.builds')

        logger = cb_logs.CloudBuildClient(client, messages)
        if args.stream:
            logger.Stream(build_ref)
            return

        # Just print out what's available now.
        logger.PrintLog(build_ref)
示例#17
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

    release_track = self.ReleaseTrack()
    client = cloudbuild_util.GetClientInstance(release_track)
    messages = cloudbuild_util.GetMessagesModule(release_track)

    parent = properties.VALUES.core.project.Get(required=True)

    wp_name = args.WORKER_POOL

    # Get the workerpool ref
    wp_resource = resources.REGISTRY.Parse(
        None,
        collection='cloudbuild.projects.workerPools',
        api_version=cloudbuild_util.RELEASE_TRACK_TO_API_VERSION[release_track],
        params={
            'projectsId': parent,
            'workerPoolsId': wp_name,
        })

    # Send the Delete request
    client.projects_workerPools.Delete(
        messages.CloudbuildProjectsWorkerPoolsDeleteRequest(
            name=wp_resource.RelativeName()))

    log.DeletedResource(wp_resource)
示例#18
0
  def _UpdateBuildTriggerWithSchedulerJobTags(
      self, build_trigger, job_location, job_id):
    job_location_tag = 'cloudscheduler-job-location_' + job_location
    job_id_tag = 'cloudscheduler-job-id_' + job_id

    build_trigger_tags = [x for x in build_trigger.tags
                          if not x.startswith('cloudscheduler-job-')]
    build_trigger_tags.append(job_location_tag)
    build_trigger_tags.append(job_id_tag)
    build_trigger.tags = build_trigger_tags

    build_tags = [x for x in build_trigger.build.tags
                  if not x.startswith('cloudscheduler-job-')]
    build_tags.append(job_location_tag)
    build_tags.append(job_id_tag)
    build_trigger.build.tags = build_tags

    client = cloudbuild_util.GetClientInstance()
    messages = cloudbuild_util.GetMessagesModule()
    project = properties.VALUES.core.project.Get(required=True)

    updated_trigger = client.projects_triggers.Patch(
        messages.CloudbuildProjectsTriggersPatchRequest(
            buildTrigger=build_trigger,
            projectId=project,
            triggerId=build_trigger.id
        )
    )

    log.debug('added job id to trigger: ' + six.text_type(updated_trigger))
示例#19
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
    build_region = args.region or cloudbuild_util.DEFAULT_REGION

    client = cloudbuild_util.GetClientInstance()
    messages = cloudbuild_util.GetMessagesModule()

    project_id = properties.VALUES.core.project.GetOrFail()
    parent_resource = resources.REGISTRY.Create(
        collection='cloudbuild.projects.locations',
        projectsId=project_id,
        locationsId=build_region)

    args.filter, server_filter = filter_rewrite.Backend(args.ongoing).Rewrite(
        args.filter)

    return list_pager.YieldFromList(
        client.projects_locations_builds,
        messages.CloudbuildProjectsLocationsBuildsListRequest(
            parent=parent_resource.RelativeName(),
            pageSize=args.page_size,
            filter=server_filter),
        field='builds',
        batch_size=args.page_size,
        limit=args.limit,
        batch_size_attribute='pageSize')
示例#20
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        release_track = self.ReleaseTrack()
        client = cloudbuild_util.GetClientInstance(release_track)
        messages = cloudbuild_util.GetMessagesModule(release_track)

        parent = properties.VALUES.core.project.Get(required=True)

        # Get the parent project ref
        parent_resource = resources.REGISTRY.Create(
            collection='cloudbuild.projects', projectId=parent)

        # Send the List request
        wp_list = client.projects_workerPools.List(
            messages.CloudbuildProjectsWorkerPoolsListRequest(
                parent=parent_resource.RelativeName())).workerPools

        # Format the workerpool names for display
        for wp in wp_list:
            try:
                wp.name = cloudbuild_util.GlobalWorkerPoolShortName(wp.name)
            except ValueError:
                pass  # Must be an old version.

        return wp_list
    def Run(self, args):
        """Exports a build trigger.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.
    """
        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        project = properties.VALUES.core.project.Get(required=True)
        location = args.region or cloudbuild_util.DEFAULT_REGION
        trigger = args.TRIGGER

        name = resources.REGISTRY.Parse(
            trigger,
            params={
                'projectsId': project,
                'locationsId': location,
                'triggersId': trigger,
            },
            collection='cloudbuild.projects.locations.triggers').RelativeName(
            )

        got_trigger = client.projects_locations_triggers.Get(
            messages.CloudbuildProjectsLocationsTriggersGetRequest(
                name=name, triggerId=trigger))
        with files.FileWriter(args.destination) as out:
            yaml.dump(encoding.MessageToDict(got_trigger), stream=out)
示例#22
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Nothing on success.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        parent = properties.VALUES.core.project.Get(required=True)

        config_id = args.CONFIG

        # Get the github enterprise config ref
        ghe_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.githubEnterpriseConfigs',
            api_version='v1',
            params={
                'projectsId': parent,
                'githubEnterpriseConfigsId': config_id,
            })

        # Send the Delete request
        client.projects_githubEnterpriseConfigs.Delete(
            messages.CloudbuildProjectsGithubEnterpriseConfigsDeleteRequest(
                name=ghe_resource.RelativeName()))
        log.DeletedResource(ghe_resource)
示例#23
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        build_region = args.region or cloudbuild_util.DEFAULT_REGION

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        cancelled = []
        for build in args.builds:
            build_ref = resources.REGISTRY.Parse(
                build,
                params={
                    'projectsId': properties.VALUES.core.project.GetOrFail,
                    'locationsId': build_region,
                    'buildsId': build,
                },
                collection='cloudbuild.projects.locations.builds')
            cancelled_build = client.projects_locations_builds.Cancel(
                messages.CancelBuildRequest(
                    name=build_ref.RelativeName(),
                    projectId=build_ref.projectsId,
                    id=build_ref.buildsId,
                ))
            log.status.write(
                'Cancelled [{r}].\n'.format(r=six.text_type(build_ref)))
            cancelled.append(cancelled_build)
        return cancelled
示例#24
0
def _RunBuild(name, arch, function_type, source):
    """Builds the Edge function image with Cloud Build.

  Args:
    name: str, name of the Edge Function
    arch: str, target architecture,
      should be one of 'x86-64', 'armhf', 'aarch64'
    function_type: str, type of function,
      should be one of 'on-demand', 'stream-processing'
    source: str, GCS URI to source archive object or
      local path to source directory

  Returns:
    Finished cloudbuild.Build message. build.results.images contains
      built image's name and digest

  Raises:
    FailedBuildException: If the build is completed and not 'SUCCESS'
    FunctionBuilderError: For invalid arguments
  """
    client = cloudbuild_util.GetClientInstance()
    messages = cloudbuild_util.GetMessagesModule()

    build_config = _EdgeFunctionBuildMessage(name, arch, function_type, source)

    log.debug('submitting build: ' + repr(build_config))

    # Start the build.
    op = client.projects_builds.Create(
        messages.CloudbuildProjectsBuildsCreateRequest(
            build=build_config,
            projectId=properties.VALUES.core.project.Get()))
    json = encoding.MessageToJson(op.metadata)
    build = encoding.JsonToMessage(messages.BuildOperationMetadata, json).build

    build_ref = resources.REGISTRY.Create(
        collection='cloudbuild.projects.builds',
        projectId=build.projectId,
        id=build.id)

    log.CreatedResource(build_ref)

    mash_handler = execution.MashHandler(
        execution.GetCancelBuildHandler(client, messages, build_ref))

    # Stream logs from GCS.
    with execution_utils.CtrlCSection(mash_handler):
        build = cb_logs.CloudBuildClient(client, messages).Stream(build_ref)

    if build.status != messages.Build.StatusValueValuesEnum.SUCCESS:
        raise FailedBuildException(build)

    return build
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()
        config_id = args.CONFIG
        bbs = cloudbuild_util.BitbucketServerConfigFromArgs(args, True)

        parent = properties.VALUES.core.project.Get(required=True)

        # Get the bitbucket server config ref
        bbs_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.locations.bitbucketServerConfigs',
            api_version='v1',
            params={
                'projectsId': parent,
                # Use default region global until Proctor is fully regionalized.
                'locationsId': cloudbuild_util.DEFAULT_REGION,
                'bitbucketServerConfigsId': config_id,
            })

        update_mask = cloudbuild_util.MessageToFieldPaths(bbs)
        req = messages.CloudbuildProjectsLocationsBitbucketServerConfigsPatchRequest(
            name=bbs_resource.RelativeName(),
            bitbucketServerConfig=bbs,
            updateMask=','.join(update_mask))
        # Send the Update request
        updated_op = client.projects_locations_bitbucketServerConfigs.Patch(
            req)
        op_resource = resources.REGISTRY.ParseRelativeName(
            updated_op.name,
            collection='cloudbuild.projects.locations.operations')

        updated_bbs = waiter.WaitFor(
            waiter.CloudOperationPoller(
                client.projects_locations_bitbucketServerConfigs,
                client.projects_locations_operations), op_resource,
            'Updating Bitbucket Server config')

        log.UpdatedResource(bbs_resource)

        return updated_bbs
示例#26
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The updated github enterprise resource.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        config_id = args.CONFIG
        ghe = cloudbuild_util.GitHubEnterpriseConfigFromArgs(args, True)

        parent = properties.VALUES.core.project.Get(required=True)

        # Get the github enterprise config ref
        ghe_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.githubEnterpriseConfigs',
            api_version='v1',
            params={
                'projectsId': parent,
                'githubEnterpriseConfigsId': config_id,
            })

        ghe.name = ghe_resource.RelativeName()
        update_mask = cloudbuild_util.MessageToFieldPaths(ghe)
        req = messages.CloudbuildProjectsGithubEnterpriseConfigsPatchRequest(
            name=ghe.name,
            gitHubEnterpriseConfig=ghe,
            updateMask=','.join(update_mask))
        # Send the Update request
        updated_op = client.projects_githubEnterpriseConfigs.Patch(req)

        op_resource = resources.REGISTRY.ParseRelativeName(
            updated_op.name,
            collection='cloudbuild.projects.locations.operations')

        updated_ghe = waiter.WaitFor(
            waiter.CloudOperationPoller(
                client.projects_githubEnterpriseConfigs,
                client.projects_locations_operations), op_resource,
            'Updating GitHub Enterprise Config')

        log.UpdatedResource(ghe_resource)

        return updated_ghe
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()
        bbs = cloudbuild_util.BitbucketServerConfigFromArgs(args, False)
        parent = properties.VALUES.core.project.Get(required=True)
        # Use default region global until Proctor is fully regionalized.
        bbs_region = cloudbuild_util.DEFAULT_REGION
        # Get the parent project ref
        parent_resource = resources.REGISTRY.Create(
            collection='cloudbuild.projects.locations',
            projectsId=parent,
            locationsId=bbs_region)
        # Send the Create request
        created_op = client.projects_locations_bitbucketServerConfigs.Create(
            messages.
            CloudbuildProjectsLocationsBitbucketServerConfigsCreateRequest(
                parent=parent_resource.RelativeName(),
                bitbucketServerConfig=bbs,
                bitbucketServerConfigId=args.name))
        op_resource = resources.REGISTRY.ParseRelativeName(
            created_op.name,
            collection='cloudbuild.projects.locations.operations')
        created_config = waiter.WaitFor(
            waiter.CloudOperationPoller(
                client.projects_locations_bitbucketServerConfigs,
                client.projects_locations_operations), op_resource,
            'Creating Bitbucket Server config')
        bbs_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.locations.bitbucketServerConfigs',
            api_version='v1',
            params={
                'projectsId': parent,
                'locationsId': bbs_region,
                'bitbucketServerConfigsId': created_config.name,
            })

        log.CreatedResource(bbs_resource)

        return created_config
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

    wp_region = args.region

    release_track = self.ReleaseTrack()
    client = cloudbuild_util.GetClientInstance(release_track)
    messages = cloudbuild_util.GetMessagesModule(release_track)

    parent = properties.VALUES.core.project.Get(required=True)

    wp_name = args.WORKER_POOL

    # Get the workerpool ref
    wp_resource = resources.REGISTRY.Parse(
        None,
        collection='cloudbuild.projects.locations.workerPools',
        api_version=cloudbuild_util.RELEASE_TRACK_TO_API_VERSION[release_track],
        params={
            'projectsId': parent,
            'locationsId': wp_region,
            'workerPoolsId': wp_name,
        })

    # Send the Get request
    wp = client.projects_locations_workerPools.Get(
        messages.CloudbuildProjectsLocationsWorkerPoolsGetRequest(
            name=wp_resource.RelativeName()))

    if release_track != base.ReleaseTrack.ALPHA:
      if wp.hybridPoolConfig is not None:
        raise exceptions.Error('NOT_FOUND: Requested entity was not found.')

    # Format the workerpool name for display
    try:
      wp.name = cloudbuild_util.WorkerPoolShortName(wp.name)
    except ValueError:
      pass  # Must be an old version.

    return wp
示例#29
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.
    """
        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        project = properties.VALUES.core.project.Get(required=True)
        trigger = client.projects_triggers.Get(
            messages.CloudbuildProjectsTriggersGetRequest(
                projectId=project, triggerId=args.TRIGGER))
        with files.FileWriter(args.destination) as out:
            yaml.dump(encoding.MessageToDict(trigger), stream=out)
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: An argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The newly created trigger.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        trigger = messages.BuildTrigger()
        if args.trigger_config:
            trigger = cloudbuild_util.LoadMessageFromPath(
                path=args.trigger_config,
                msg_type=messages.BuildTrigger,
                msg_friendly_name='build trigger config',
                skip_camel_case=['substitutions'])
        else:
            trigger = ParseTriggerFromFlags(args)

        # Send the Create request
        project = properties.VALUES.core.project.Get(required=True)
        location = args.region or cloudbuild_util.DEFAULT_REGION
        parent = resources.REGISTRY.Create(
            collection='cloudbuild.projects.locations',
            projectsId=project,
            locationsId=location).RelativeName()
        created_trigger = client.projects_locations_triggers.Create(
            messages.CloudbuildProjectsLocationsTriggersCreateRequest(
                parent=parent, buildTrigger=trigger))

        trigger_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.locations.triggers',
            api_version='v1',
            params={
                'projectsId': project,
                'locationsId': location,
                'triggersId': created_trigger.id,
            })
        log.CreatedResource(trigger_resource)

        return created_trigger