> For the complete documentation index, see [llms.txt](https://docs.flxbl.io/flxbl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flxbl.io/flxbl/sfp/publishing-and-fetching-artifacts/publish-artifact.md).

# Publish Artifact

`sfp publish` pushes the artifacts produced by `sfp build` to a registry, and can tag the published versions in your git repository.

Artifacts are read from the directory given by `-d/--artifactdir`, which defaults to `artifacts`.

## Where artifacts are published

Publishing has two destinations, and a run can use either or both.

| Destination                                                                             | When it is used                                          |
| --------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| **Internal registry** — the registry the sfp server keeps                               | Whenever an sfp server is configured. No flags required. |
| **External registry** — an npm-compatible registry, or anything reachable from a script | When `--npm` or `--scriptpath` is passed.                |

The command reports the mode it resolved as `Internal`, `External Only (no sfp server configured)`, or `Internal + External`.

```bash
# Server configured — publishes to the internal registry
sfp publish

# Server configured, and also to an external npm registry
sfp publish --npm --scope myorg

# No server — external only
sfp publish --npm --scope myorg --npmrcpath .npmrc
```

{% hint style="info" %}
With no sfp server configured and neither `--npm` nor `--scriptpath` passed, publish has nowhere to send the artifacts and does nothing.
{% endhint %}

## Publishing to an npm-compatible registry

Pass `--npm` to publish externally. Authentication comes from an `.npmrc`, an auth token, or the sfp server:

* `--npmrcpath` — path to an `.npmrc` holding the registry URL and a token with publish permission. When an sfp server is configured and this flag is not set, the `.npmrc` is fetched from the server. Otherwise it defaults to the one in your home directory.
* `--npmauthtoken` — a registry token. Defaults to `GITHUB_TOKEN` in GitHub Actions, `CI_JOB_TOKEN` in GitLab CI, or `NPM_TOKEN`.
* `--provider` — `github`, `gitlab` or `npm`. Auto-detected from the CI environment when not set. With `github` or `gitlab` outside CI you must also pass `--repository`.
* `--scope` — the user or organisation scope of the npm package. Required with `--npm` when no sfp server is configured.

There is no registry-URL flag. The registry comes from the `.npmrc`.

### Registry providers

Follow your registry's own instructions to produce an `.npmrc` with the correct URL and a token that can publish:

* [GitHub Packages](https://docs.github.com/en/packages/guides/configuring-npm-for-use-with-github-packages)
* [GitLab npm registry](https://docs.gitlab.com/ee/user/packages/npm_registry/)
* [Azure Artifacts](https://docs.microsoft.com/en-us/azure/devops/artifacts/npm/npmrc?view=azure-devops)
* [JFrog Artifactory](https://www.jfrog.com/confluence/display/JFROG/npm+Registry)
* [MyGet](https://docs.myget.org/docs/reference/myget-npm-support)

## Publishing somewhere that is not npm

Where artifacts live in storage that is not an npm registry, pass `--scriptpath` instead of `--npm`. sfp calls the script once per artifact.

```bash
sfp publish --scriptpath scripts/publish-artifact.sh
```

## Publishing only promoted packages

`-p/--publishpromotedonly` restricts publishing to package versions that have been promoted. It requires `--devhubalias`, since promotion state is read from the DevHub.

```bash
sfp publish --npm --scope myorg --publishpromotedonly --devhubalias mydevhub
```

## Tagging an artifact

The publish command can tag published artifacts in version control. These tags are what `sfp build --diffcheck` uses to work out which packages changed.

| Flag            | Description                                                                                      |
| --------------- | ------------------------------------------------------------------------------------------------ |
| `--gittag`      | Tag the current commit with an annotated tag holding the package name and version. Does not push |
| `--pushgittag`  | Push the tags created by this command to the repository                                          |
| `--gittaglimit` | Minimum number of tags to retain per package                                                     |
| `--gittagage`   | Number of days a tag is retained; older tags are deleted                                         |

```bash
sfp publish --npm --scope myorg --gittag --pushgittag
```

## Flags

| Flag                          | Description                                                         | Required                   |
| ----------------------------- | ------------------------------------------------------------------- | -------------------------- |
| `-d`, `--artifactdir`         | Directory containing the artifacts to publish (default `artifacts`) | Yes                        |
| `--npm`                       | Publish to an npm-compatible registry                               | No                         |
| `--scope`                     | User or organisation scope of the npm package                       | With `--npm` and no server |
| `--npmrcpath`                 | Path to the `.npmrc` used to authenticate. Requires `--npm`         | No                         |
| `--npmauthtoken`              | Registry auth token                                                 | No                         |
| `--provider`                  | `github`, `gitlab` or `npm`. Requires `--npm`                       | No                         |
| `-f`, `--scriptpath`          | Script that publishes each artifact, for non-npm registries         | No                         |
| `-p`, `--publishpromotedonly` | Publish only promoted package versions. Requires `--devhubalias`    | No                         |
| `-v`, `--devhubalias`         | DevHub used to read promotion state                                 | No                         |
| `-t`, `--tag`                 | Tag recorded against the publish                                    | No                         |
| `--gittag`                    | Create an annotated git tag per published artifact                  | No                         |
| `--pushgittag`                | Push the created git tags                                           | No                         |
| `--gittaglimit`               | Minimum number of tags retained per package                         | No                         |
| `--gittagage`                 | Age in days beyond which tags are deleted                           | No                         |

{% hint style="warning" %}
`--npmtag` is deprecated. sfp tags the artifact with the branch name automatically.
{% endhint %}

## Related

* [Fetching Artifacts](/flxbl/sfp/publishing-and-fetching-artifacts/fetching-artifacts.md) — retrieving published artifacts
* [Building artifacts](/flxbl/sfp/building-artifacts/overview.md) — producing the artifacts to publish


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.flxbl.io/flxbl/sfp/publishing-and-fetching-artifacts/publish-artifact.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
