Skip to main content

Create services

Services represent your microservices and other workloads. Each service contains a Service Definition that defines your deployment artifacts, manifests or specifications, configuration files, and service-specific variables.

Create a service

You can create services from:

  • Within a pipeline
  • Outside a pipeline
  • An account
  • An Organization

If you are new to Harness, review Harness key concepts and create your first CD pipeline.

To create a service from inside of a pipeline, select the Services tab of a new CD stage, then select New Service.

Once the service and its service definition are saved, you can select it in any pipeline.

When you select the service in a pipeline, you can select Edit Service to edit its Service Definition.

When you create the new service you define its Service Definition. For example, a Kubernetes Service Definition with a Kubernetes manifest and Docker artifact.

Using runtime inputs and expressions with services

Services are often configured using runtime inputs or expressions, so you can change service settings for different deployment scenarios at pipeline runtime.

note

For more information on runtime inputs and expressions, go to Fixed Values, Runtime Inputs, and Expressions.

Often, the service option in a pipeline is also set as a runtime input, so you can select which service to use when you deploy the pipeline.

Also, the pipeline that deploys the service might be triggered in response to changes in a service's artifact or manifest.

There are a few things to note when using services with or as runtime inputs:

  • Service runtime inputs are not configurable in the pipeline that deploys the service.
  • Service runtime inputs are not configurable in the trigger.

Why are service inputs not configurable?

Many Harness settings and options are dependent on the specific values set in a service. When a value is set as runtime input, Harness can't identify what configurations to render in the user interface.

Selecting settings when the service is an expression

If you use an expression in a service setting, Harness must be able to resolve the expressions when you run the pipeline using the service.

There are a few options you can use to support expressions when a service is set as a runtime input in a pipeline, or when the service itself uses runtime inputs. These options are covered in the following sections.

Use trigger payload data to configure the service at runtime

You can pass in this data when the pipeline execution is triggered using a custom cURL trigger.

For more information, go to Passing data in Custom triggers.

Here's the YAML for a service in a pipeline that uses trigger payload data for the service reference, primary artifact, and tag:

spec:
service:
serviceRef: <+trigger.payload.serviceId>
serviceInputs:
serviceDefinition:
type: TAS
spec:
artifacts:
primary:
primaryArtifactRef: <+trigger.payload.artifactId>
sources:
- identifier: <+trigger.payload.artifactId>
type: Nexus2Registry
spec:
tag: <+trigger.payload.tag>

To supply the data, you simply provide the payload key-value pairs in the cURL command you use to execute the pipeline:

curl -X POST -H 'Content-Type: application/json' --url 'webhook_url' -d '{"serviceId": "Kubernetes", "artifactId": "nginx", "tag": "abc"}'

Use pipeline variables and trigger payload data to configure the service at runtime

You can create pipeline variables and map those to service settings. When you run the pipeline, you can provide values for the variables to define the service.

For example, here are pipeline variables for a service's artifact and tags.

picture 6

Next, you map the pipeline variables to the services' artifact settings using expressions:

picture 4

You can also map a pipeline variable for the service name as an expression:

picture 5

When you run the pipeline, you are prompted to provide values for the pipeline variables.

picture 7

You can also map these same pipeline variables to trigger payload data expressions.

picture 8

When you initiate the trigger using the cURL command, the key-value pairs in the command are used for the pipeline variables. Finally, those pipeline variable values are used to define the service.

Next steps