Use PowerShell PSResourceGet with JFrog CLI
Register an Artifactory NuGet feed with jf setup psresource and run the PSResourceGet cmdlets with optional build-info.
Run PowerShell PSResourceGet cmdlets through JFrog CLI against a JFrog Artifactory NuGet repository. JFrog CLI registers the feed with jf setup psresource and exposes each cmdlet as its own command.
This topic covers the following tasks:
When to Use
Use these commands when PowerShell modules or scripts are stored in an Artifactory NuGet repository and the machine has PowerShell 7+ with the PSResourceGet module. JFrog CLI 2.126.0 and later include the commands. The following table lists each command and the build-info it records.
| Command | Native cmdlet | Build-info |
|---|---|---|
jf Install-PSResource | Install-PSResource | Direct dependencies |
jf Save-PSResource | Save-PSResource | Direct dependencies |
jf Update-PSResource | Update-PSResource | Direct dependencies, using the version resolved after the update |
jf Publish-PSResource | Publish-PSResource | The published package, with build properties stamped in Artifactory |
There's no jf psresource command and no jf psresource-config command. The cmdlets always run natively. You don't set JFROG_RUN_NATIVE.
PSResourceGet uses a NuGet v3 feed. Artifactory doesn't have a separate PowerShell package type. The PowerShellGet commands Install-Module and Publish-Module are a different client. For those commands without JFrog CLI, see NuGet Repositories — PowerShell Client.
Note
Package Alias doesn't intercept
Install-PSResource,Save-PSResource,Update-PSResource, orPublish-PSResource. Run thejfcommands on this page. For more information, see Use JFrog CLI Package Alias.
Prerequisites
- JFrog CLI 2.126.0 or later. Verify with
jf --version. - PowerShell 7 or later, available as
pwsh, with theMicrosoft.PowerShell.PSResourceGetmodule installed. On Windows, JFrog CLI usespowershell.exeonly whenpwshisn't onPATHand that Windows PowerShell installation has the module. The commands run on macOS, Linux, and Windows. - A JFrog CLI server configured with
jf config add. - An Artifactory NuGet repository, virtual, local, or remote. Install, save, and update need read permission. Publish needs write permission.
Verify the module:
pwsh -NoProfile -Command "Get-Module -ListAvailable -Name Microsoft.PowerShell.PSResourceGet"Configure PSResourceGet for Artifactory
jf setup psresource registers one trusted PSResourceGet repository for an Artifactory NuGet v3 feed. The repository name is jfrt-<hostname>-<repository-key>. Setup stores the registration in the current user's PSResourceRepository.xml, not in a machine-wide file. Run setup again for each user account.
Setup doesn't store credentials in that file. jf Install-PSResource, jf Save-PSResource, jf Update-PSResource, and jf Publish-PSResource inject -Credential for the command when you pass --repo-resolve or --repo.
To configure PSResourceGet for Artifactory:
- Run
jf setup psresource.
jf setup psresource --server-id=<SERVER_ID> --repo=<REPOSITORY_KEY> --project=<PROJECT_KEY>Where:
<SERVER_ID>: JFrog CLI server ID fromjf config add. Omit--server-idto use the default server.<REPOSITORY_KEY>: NuGet repository key. Omit--repoto choose the repository interactively.<PROJECT_KEY>: JFrog Project key, when the repository belongs to a project. Omit--projectwhen the repository isn't in a project.
For example:
jf setup psresource --server-id=my-server --repo=nuget-virtualOn success, the command prints the repository name:
PSResource source name: jfrt-acme.jfrog.io-nuget-virtual- Use that printed name as the native
-Repositoryvalue on later PSResourceGet commands.
Re-running setup for the same name replaces that registration and leaves other PSResourceGet repositories in place.
Install, Save, and Update Modules
JFrog CLI forwards native parameters such as -Name, -Version, -Repository, -Scope, and -Path unchanged. --repo-resolve records the Artifactory repository on the build-info and supplies credentials. It doesn't select the PSResourceGet repository. Pass -Repository for that.
To install, save, or update a module:
- Install a module.
jf Install-PSResource -Name <MODULE_NAME> -Repository <SOURCE_NAME> --repo-resolve=<REPOSITORY_KEY> --server-id=<SERVER_ID> --build-name=<BUILD_NAME> --build-number=<BUILD_NUMBER>Where:
<MODULE_NAME>: PowerShell module name.<SOURCE_NAME>: PSResourceGet repository name printed byjf setup psresource.<REPOSITORY_KEY>: Artifactory NuGet repository key recorded on the build-info.<SERVER_ID>: JFrog CLI server ID. Omit--server-idto use the default server.<BUILD_NAME>: Build name. Required with<BUILD_NUMBER>.<BUILD_NUMBER>: Build number. Required with<BUILD_NAME>.
For example:
jf Install-PSResource -Name MyModule -Repository jfrt-acme.jfrog.io-nuget-virtual --repo-resolve=nuget-virtual --server-id=my-server --build-name=app --build-number=1- Save a module to a local path.
jf Save-PSResource -Name <MODULE_NAME> -Path <LOCAL_PATH> -Repository <SOURCE_NAME> --repo-resolve=<REPOSITORY_KEY> --build-name=<BUILD_NAME> --build-number=<BUILD_NUMBER>Where:
<LOCAL_PATH>: Directory where PSResourceGet writes the module.
For example:
jf Save-PSResource -Name MyModule -Path ./local-modules -Repository jfrt-acme.jfrog.io-nuget-virtual --repo-resolve=nuget-virtual --build-name=app --build-number=1- Update a module.
jf Update-PSResource -Name <MODULE_NAME> -Repository <SOURCE_NAME> --repo-resolve=<REPOSITORY_KEY> --build-name=<BUILD_NAME> --build-number=<BUILD_NUMBER>For example:
jf Update-PSResource -Name MyModule -Repository jfrt-acme.jfrog.io-nuget-virtual --repo-resolve=nuget-virtual --build-name=app --build-number=1- Publish the collected build-info.
jf rt build-publish <BUILD_NAME> <BUILD_NUMBER>For example:
jf rt build-publish app 1You can also pass the following options.
| Option | Description |
|---|---|
--module | Module name inside the build-info. Requires both build flags. |
--project | JFrog Project key stored on the build-info. |
Note
PSResourceGet has no lock file, so build-info lists the modules named on the command. JFrog CLI doesn't record transitive dependencies. JFrog CLI reads checksums with a HEAD request to Artifactory.
jf Save-PSResource -Pathis the exception. JFrog CLI computes those checksums from the.nupkgwritten to that path.
Publish a Module
Publish-PSResource builds the .nupkg in memory and uploads it. JFrog CLI doesn't read a local .nupkg for checksums. It confirms the artifact in Artifactory and stamps build properties when both build flags are set.
--repo is the deployment repository recorded on the build-info and the repository whose credentials are injected. It must be the same Artifactory repository that -Repository resolves to. --repo doesn't replace -Repository.
To publish a module:
- Run
jf Publish-PSResource.
jf Publish-PSResource -Path <MODULE_PATH> -Repository <SOURCE_NAME> --repo=<REPOSITORY_KEY> --server-id=<SERVER_ID> --build-name=<BUILD_NAME> --build-number=<BUILD_NUMBER>Where:
<MODULE_PATH>: Path to the module to publish.<SOURCE_NAME>: PSResourceGet repository name printed byjf setup psresource.<REPOSITORY_KEY>: Artifactory NuGet repository key. This must be the repository that<SOURCE_NAME>uploads to.<SERVER_ID>: JFrog CLI server ID. Omit--server-idto use the default server.<BUILD_NAME>: Build name. Required with<BUILD_NUMBER>.<BUILD_NUMBER>: Build number. Required with<BUILD_NAME>.
For example:
jf Publish-PSResource -Path ./MyModule -Repository jfrt-acme.jfrog.io-nuget-local --repo=nuget-local --server-id=my-server --build-name=app --build-number=1- Publish the collected build-info.
jf rt build-publish <BUILD_NAME> <BUILD_NUMBER>For example:
jf rt build-publish app 1Passing only --build-name or only --build-number is an error, and the cmdlet doesn't run.
Troubleshooting
The following table lists common failures and how to fix them.
| Symptom | Cause | Fix |
|---|---|---|
'jf Install-PSResource'/'jf Publish-PSResource' requires PowerShell 7+ | pwsh is missing, or Microsoft.PowerShell.PSResourceGet isn't installed | Install PowerShell 7 or later and the PSResourceGet module, then rerun the command |
| The cmdlet resolves from a different repository than the build-info | -Repository and --repo-resolve don't refer to the same Artifactory repository | Pass the jfrt-... name from setup to -Repository, and pass that repository key to --repo-resolve |
| 401 from Artifactory | --repo-resolve or --repo was omitted, so no credential was injected, or the token cannot access the repository | Pass the matching repository option and confirm the server configuration with jf config show |
| Publish properties are missing | --repo doesn't match the repository -Repository uploads to | Use the same Artifactory repository for both |
| Setup works for one user and not another | Registration is per user profile | Run jf setup psresource as that user |
To enable debug logging, run export JFROG_CLI_LOG_LEVEL=DEBUG, then rerun the command. In PowerShell, use $env:JFROG_CLI_LOG_LEVEL = "DEBUG".
Frequently Asked Questions
This section provides answers to frequently asked questions about PSResourceGet and JFrog CLI.
FAQs
Q: Is this the same as Install-Module?
A: No. These commands wrap PSResourceGet (Install-PSResource and the related cmdlets). Install-Module and Publish-Module belong to PowerShellGet. See NuGet Repositories — PowerShell Client for that client.
Q: Does jf setup psresource save my token in PSResourceRepository.xml?
A: No. Setup registers the feed as a trusted repository and doesn't persist credentials. The jf cmdlets inject -Credential for that invocation when you pass --repo-resolve or --repo. For more information, see Configure PSResourceGet for Artifactory.
Q: When do I set JFROG_RUN_NATIVE?
A: No. These commands always run the native PSResourceGet cmdlet.
Related Topics
Updated 10 days ago
