> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/templates/artifact-source-template.md).

# Create an artifact source template

Harness templates help you standardize your pipelines for your DevOps teams. Team members can select stage, step, and other templates instead of having to create them.

An artifact source template helps you define the repositories, paths, and tags for an artifact that your team can use in Harness CD services. You can define the artifact source template and your team members can select them when they use services in their pipelines.

This topic describes how to create an artifact source template and use it in a stage template and a Harness service.

### Visual summary <a href="#visual-summary" id="visual-summary"></a>

{% embed url="<https://youtu.be/R3eQfS4g5Vw>" %}

### Important notes <a href="#important-notes" id="important-notes"></a>

* Artifact source templates are not supported in pipeline triggers at this time. Support for using artifact source templates in pipeline triggers will be added soon.
* Artifact source templates cannot be stored in a remote Git repo at this time. They are stored in your Harness account.

### Artifact source template scope <a href="#artifact-source-template-scope" id="artifact-source-template-scope"></a>

You can create artifact source templates at the Harness account, org, and project levels.

Create the artifact source template at the level you want to share it. For example, if you want to share it across all services in all projects in an org, create it at the org level.

### Create an artifact source template <a href="#create-an-artifact-source-template" id="create-an-artifact-source-template"></a>

To create an artifact source template, do the following:

{% tabs %}
{% tab title="Visual" %}

1. In a Harness project, org, or account settings, select **Templates**.
   1. Project:
      1. Select a module, such as **Deployments**.
      2. In **Project Setup**, click **Templates**.
   2. Org:
      1. Select an org.
      2. In **Organization Resources**, select **Templates**.
   3. Account:
      1. Select **Account Resources**.
      2. Select **Templates**.
2. Select **New Template**, and then select **Artifact Source**.

   The artifact source template appears.

   ![picture 1](/files/JweeGWlqpQWS0zeVK7GQ)
3. Enter a name for the artifact source template. Use a name that describes the artifact source so that team members understand what artifact is represents.
4. In **Version Label**, enter a version for the template. You can update the version each time you change and save a template.
5. In **Logo**, upload an icon image for the template.
6. If you are creating this template at the Harness project level, in **Save To**, select where you want to save the template. For more information, go to [saving templates to project, org, or account level](#saving-templates-to-project-org-or-account-level).
7. Select **Start**.

#### Artifact registry type <a href="#artifact-registry-type" id="artifact-registry-type"></a>

Harness support multiple artifact registry providers, including Google Container Registry (GCR), AWS Elastic Container Registry (ECR), and Azure Container Registry (ACR).

{% hint style="warning" %}
Google Container Registry (GCR) is being deprecated. For more details, refer to the [Deprecation Notice](/continuous-delivery/use-continuous-delivery/cd-building-blocks/services/artifact-sources.md#google-container-registry-gcr).
{% endhint %}

Harness includes a platform-agnostic artifact registry type named Docker Registry. Use Docker Registry for images on any registry, including Docker Hub.

1. Select the artifact repo provider where your images are stored.

#### Repository <a href="#repository" id="repository"></a>

1. In the repository setting, select or create the Harness registry connector. For example, if you selected **Docker Registry** in **Artifact Repository Type**, the repository setting is named **Docker Registry Repository**.

For information on registry connectors, go to [connect to an artifact repo](/harness-ai/use-harness-platform/connectors/artifact-repositories/connect-to-an-artifact-repo.md).

You can also select **Runtime input** or **Expression** for this setting.

![picture 2](/files/11CVuDSatWsvAxfkNAUS)

#### Artifact details <a href="#artifact-details" id="artifact-details"></a>

Different repository types have different **Artifact Details** settings.

For information on how to configure each repository's settings, see the examples in [Harness Kubernetes services](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-services.md).

#### Tags <a href="#tags" id="tags"></a>

The **Value** setting in **Tags** is a runtime input. You can select the tag to use when the pipeline using this artifact source template executes.

You can also use **Regex**.

For example, if the build is `todolist-v2.0`, the regex `todolist-v\d.\d` will match.

If the regex expression does not result in a match, Harness ignores the value.

Harness supports standard Java regex. For example, if you enable **Regex** with the intent is to match a filename, the wildcard must be `.*` instead of only `*`. Similarly, if you want to match all files ending in `-DEV.tgz`, your wildcard regex phrase would be: `.*-DEV\.tgz`
{% endtab %}

{% tab title="YAML" %}

1. In your template, select **YAML**
2. Paste the following YAML example and select **Save**:

```yaml
template:
  name: Todo List
  identifier: Todo_List
  versionLabel: "1"
  type: ArtifactSource
  projectIdentifier: CD_Docs
  orgIdentifier: default
  tags: {}
  spec:
    type: DockerRegistry
    spec:
      imagePath: harness/todolist-sample
      tag: <+input>
      connectorRef: Docker_Hub_with_Pwd
```

Note that `connectorRef` refers to the Id of a Harness connector.
{% endtab %}
{% endtabs %}

### Saving templates to project, org, or account level <a href="#saving-templates-to-project-org-or-account-level" id="saving-templates-to-project-org-or-account-level"></a>

If you are creating a template at the Harness project level, in **Save To**, you can select where you want to save the template:

* **Project**: The template is saved to this project. You will see it in the **Templates** list in all of the modules in this project that support templates (Deployments, Builds, Security Tests, etc).
* **Organization**: The template is saved to the org where this project is located. The template will only appear in the **Templates** list at the org level, but the template can be selected in any project in that org.
* **Account**: The template is saved at the account level. The template will only appear in the **Templates** list at the account level, but the template can be selected in any project in the account.

If you create the template at the project level but select **Organization** or **Account** in **Save To**, the template will not appear in the **Templates** list of the project. Navigate to the **Templates** list in the org or account where you saved it to see the template.

This can be a little confusing the first time you create a template because you saved the template in a project but it doesn't appear in that project's **Templates** list.

You will still be able to select the template in services in this project.

### Runtime inputs and expressions in template settings <a href="#runtime-inputs-and-expressions-in-template-settings" id="runtime-inputs-and-expressions-in-template-settings"></a>

**Artifact Repository Type** is the only setting in the template that must be a fixed value. The remaining settings can be runtime inputs and expressions also.

For information on runtime inputs and expressions, go to [fixed values runtime inputs and expressions](/harness-ai/use-harness-platform/variables-and-expressions/runtime-inputs.md).

Runtime inputs can be useful in artifact source templates because they let your team members select the repository, path, and tags to use when they run pipelines using artifact source templates.

Expressions can be useful in artifact source templates because you can use default Harness expressions, like `<+stage.name>`, and service variables, like `<+serviceVariables.myapp>`, in place of the connector name and/or image path. When the pipeline using the artifact source template runs, those expressions are resolved and their related connector and/or image path is selected.

### Use artifact templates in stage templates <a href="#use-artifact-templates-in-stage-templates" id="use-artifact-templates-in-stage-templates"></a>

After creating an artifact source template, you can add it as the artifact source in stage templates.

Using stage templates with artifact source templates is useful for getting your team onboarded quickly.

Artifact sources are used in CD stages. Ensure you are using a CD stage template (**Deploy**).

![cd stage template](/files/g5IWQbT86umvxDg5IViR)

To add an artifact source template to a stage template, do the following:

1. Open the stage template in Template Studio.
2. In **Service**, in **Select Service**, select **Add Service**.
3. In the new service, in **Artifacts**, select **Use template**.

   ![use template](/files/0QsgRIOGV3isl0D3FbSr)
4. Select the artifact source template you want to use, and then select **Use Template**.

   ![template selected](/files/ZVH9RMkvATttE88uX79W)
5. In **Configure Artifact Source**, enter a name for the artifact.
6. In **Tag**, you can change the setting to **Fixed Value**, and then select the tag to use. Or you can use a runtime input or expression.
7. Select **Apply Changes**.

   The artifact source template is added to the stage template.

   ![added template](/files/PYSvfekw3X1jAIzd6oKK)

### Use artifact templates in CD services <a href="#use-artifact-templates-in-cd-services" id="use-artifact-templates-in-cd-services"></a>

After creating an artifact source template, you can add it as the artifact source of a Harness service.

To add an artifact source template to a service, do the following:

{% tabs %}
{% tab title="Visual" %}

1. Select the **Deployments** module.
2. Select **Services**.
3. Select **Manage Services**.
4. Select a service.
5. Select **Configuration**.
6. In **Service Definition**, in **Artifacts**, select **Use template**.

   ![use template](/files/0QsgRIOGV3isl0D3FbSr)
7. Select the artifact source template you want to use, and then select **Use Template**.

   ![template selected](/files/ZVH9RMkvATttE88uX79W)
8. Enter a name for template.
9. In **Tag**, you can change the setting to **Fixed Value**, and then select the tag to use. Or you can use a runtime input or expression.
10. Select **Apply Changes**. The template is added to the service.
    {% endtab %}

{% tab title="YAML" %}

1. Select the **Deployments** module.
2. Select **Services**.
3. Select **Manage Services**.
4. Select a service.
5. Select **Configuration**.
6. Select **YAML**.
7. Paste the following YAML example and select **Save**:

```yaml
service:
  name: Example K8s
  identifier: Example_K8s
  serviceDefinition:
    type: Kubernetes
    spec:
      artifacts:
        primary:
          primaryArtifactRef: <+input>
          sources:
            - name: todolist
              identifier: todolist
              template:
                templateRef: Todo_List
                versionLabel: "1"
                templateInputs:
                  type: DockerRegistry
                  spec:
                    tag: <+input>
      manifests:
        - manifest:
            identifier: manifest
            type: K8sManifest
            spec:
              store:
                type: Harness
                spec:
                  files:
                    - /Templates/deployment.yaml
              skipResourceVersioning: false
  gitOpsEnabled: false
```

You can see the artifact source template in the `artifacts` section:

```
...
            - name: todolist
              identifier: todolist
              template:
                templateRef: Todo_List
                versionLabel: "1"
                templateInputs:
                  type: DockerRegistry
                  spec:
                    tag: <+input>
...
```

{% endtab %}
{% endtabs %}

### Reconcile artifact source template changes in a service <a href="#reconcile-artifact-source-template-changes-in-a-service" id="reconcile-artifact-source-template-changes-in-a-service"></a>

When changes are made to an artifact source template the service using the template is not automatically updated in the Harness Manager.

You can reconcile these changes by using the **Reconcile** option in the service (next to **Save**).

Once the reconcile action is initiated, the changes are available in the service.

### Limitation <a href="#limitation" id="limitation"></a>

Artifact templates created in a repository with a different branch name than the service template will use the service's branch name during lookup, which is not the expected behavior. This limitation occurs because Harness currently defaults to the branch and repository used in the service for artifact templates, and cross-branch referencing is not supported.
