Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JFrog CLI not reading environment variables correctly #120

Closed
kingledion opened this issue Jan 17, 2024 · 12 comments · Fixed by #124
Closed

JFrog CLI not reading environment variables correctly #120

kingledion opened this issue Jan 17, 2024 · 12 comments · Fixed by #124
Labels
bug Something isn't working

Comments

@kingledion
Copy link

kingledion commented Jan 17, 2024

Describe the bug

A previously working reference to setup-jfrog-cli@v3 stopped working. The root cause is that the JF_URL environment variable does not appear to be recognized. The changed code is here: https://github.com/jfrog/setup-jfrog-cli/pull/117/files#diff-39b2554fd18da165b59a6351b1aafff3714e2a80c1435f2de9706355b4d32351R86

It looks like there are unit tests for this specific use case, I cannot tell from looking at the code exactly what is going wrong.

Current behavior

The following error:

Error: 'download-repository' input provided, but no JFrog environment details found. Hint - Ensure that the JFrog connection details environment variables are   Error: 'download-repository' input provided, but no JFrog environment details found. Hint - Ensure that the JFrog connection details environment variables are set: either a Config Token with a JF_ENV_ prefix or separate env config (JF_URL, JF_USER, JF_PASSWORD, JF_ACCESS_TOKEN)set: either a Config Token with a JF_ENV_ prefix or separate env config (JF_URL, JF_USER, JF_PASSWORD, JF_ACCESS_TOKEN)

Reproduction steps

We are using the action in the following GitHub Action job step:

- name: Setup JFrog CLI
        if: steps.validate.outcome == 'success'
        uses: jfrog/setup-jfrog-cli@v3
        env:
          JF_URL: https://artifactory.tools.bestbuy.com/
          JF_USER: ${{ env.ARTIFACTORY_USERNAME }}
          JF_ACCESS_TOKEN: ${{ env.ARTIFACTORY_ACCESS_TOKEN }}
        with:
          download-repository: generic-jfrog-cli-remote
          version: latest
``

### Expected behavior

Action to complete successfully.This action stopped working with the push of 3.5.0 a few hours ago and we solved issue by pinning version to 3.4.2. 

### Setup JFrog CLI version

3.5.0

### JFrog CLI version

default (2.52.7)

### Workflow operating system type and version

Ubuntu 22.04

### JFrog Artifactory version (if relevant)

Artifactory EnterpriseX 7.71.11

### JFrog Xray version (if relevant)

_No response_
@kingledion kingledion added the bug Something isn't working label Jan 17, 2024
@sverdlov93
Copy link
Contributor

sverdlov93 commented Jan 18, 2024

Hi @kingledion,
Thanks for reporting this issue.
Our apologies for the inconvenience caused by this bug.
Can you please try again on debug mode:
image

@yahavi yahavi mentioned this issue Jan 18, 2024
2 tasks
@yahavi
Copy link
Member

yahavi commented Jan 18, 2024

@kingledion
The release of Setup JFrog CLI version 3.5.1 is now available, featuring a range of bug fixes addressing authentication issues (details can be found at #122).

Kindly inform us if this resolves your issues in the most recent version. Feel free to keep applying the v3 tag to access the latest updates.

@fschoenm
Copy link

fschoenm commented Jan 18, 2024

We have the same issue since today. The latest v3 action didn't fix this.

Download action repository 'jfrog/setup-jfrog-cli@v3' (SHA:69c1043e0eb0c4fc94a9d0ad0e87361798ac6084)
...
Error: 'download-repository' input provided, but no JFrog environment details found. Hint - Ensure that the JFrog connection details environment variables are set: either a Config Token with a JF_ENV_ prefix or separate env config (JF_URL, JF_USER, JF_PASSWORD, JF_ACCESS_TOKEN)

The last working commit hash was ea63b04.

@sverdlov93
Copy link
Contributor

Hi @fschoenm
Can you please try again on debug mode and share full logs and also your workflow file?
image

@fschoenm
Copy link

I don't know if it matters but the setup-jfrog-cli job works, it's the post job that fails.

@fschoenm
Copy link

Here's some logging output (only an excerpt, the re-run doesn't go through completely because we can't re-upload the same files):

# Set up job

...
Download action repository 'jfrog/setup-jfrog-cli@v3' (SHA:69c1043e0eb0c4fc94a9d0ad0e87361798ac6084)
##[debug]Download 'https://api.github.com/repos/jfrog/setup-jfrog-cli/tarball/69c1043e0eb0c4fc94a9d0ad0e87361798ac6084' to '/ssd/github-runner/_work/_actions/_temp_58b202aa-7869-46b3-a0c8-3be1a615df2e/40fc1de9-6c14-43f9-aecf-5f402d4f2b3c.tar.gz'
##[debug]Unwrap 'jfrog-setup-jfrog-cli-69c1043' to '/ssd/github-runner/_work/_actions/jfrog/setup-jfrog-cli/v3'
##[debug]Archive '/ssd/github-runner/_work/_actions/_temp_58b202aa-7869-46b3-a0c8-3be1a615df2e/40fc1de9-6c14-43f9-aecf-5f402d4f2b3c.tar.gz' has been unzipped into '/ssd/github-runner/_work/_actions/jfrog/setup-jfrog-cli/v3'.
##[debug]action.yml for action: '/ssd/github-runner/_work/_actions/actions/checkout/v3/action.yml'.
##[debug]action.yml for action: '/ssd/github-runner/_work/_actions/actions/download-artifact/v3/action.yml'.
##[debug]action.yml for action: '/ssd/github-runner/_work/_actions/actions/download-artifact/v3/action.yml'.
##[debug]action.yml for action: '/ssd/github-runner/_work/_actions/jfrog/setup-jfrog-cli/v3/action.yml'.
##[debug]Set step '__actions_checkout' display name to: 'Checkout project'
##[debug]Set step '__actions_download-artifact' display name to: 'Download artifacts (Debug)'
##[debug]Set step '__actions_download-artifact_2' display name to: 'Download artifacts (RelWithDebInfo)'
##[debug]Set step '__jfrog_setup-jfrog-cli' display name to: 'Setup JFrog CLI'
##[debug]Set step '__run' display name to: 'Upload to Artifactory (Debug)'
##[debug]Set step '__run_2' display name to: 'Upload to Artifactory (RelWithDebInfo)'
##[debug]Set step '__run_3' display name to: 'Publish build info'
##[debug]Set step '__run_4' display name to: 'Add build info to workflow summary'


# Setup JFrog CLI

##[debug]Evaluating: secrets.TRS_ARTIFACTORY_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'TRS_ARTIFACTORY_TOKEN'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating condition for step: 'Setup JFrog CLI'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Setup JFrog CLI
##[debug]Register post job cleanup for action: jfrog/setup-jfrog-cli@v3
##[debug]Loading inputs
##[debug]Loading env
Run jfrog/setup-jfrog-cli@v3
  with:
    version: latest
    download-repository: bt-vs-jfrog-cli-remote
  env:
    JFROG_CLI_BUILD_NAME: attribute-extractor-cvflow
    JF_URL: https://artifactory.company.com/
    JF_ACCESS_TOKEN: ***
::group::Setup JFrog CLI
Setup JFrog CLI
  Downloading JFrog CLI from https://artifactory.company.com/artifactory/bt-vs-jfrog-cli-remote/v2/[RELEASE]/jfrog-cli-linux-amd64/jfrog
  ##[debug]Downloading https://artifactory.company.com/artifactory/bt-vs-jfrog-cli-remote/v2/[RELEASE]/jfrog-cli-linux-amd64/jfrog
  ##[debug]Destination /ssd/github-runner/_work/_temp/7be025e4-95b0-4ccc-adeb-e955b6a9c69c
  ##[debug]set auth
  ##[debug]download complete
  ##[debug]Caching tool jf [RELEASE] x64
  ##[debug]source file: /ssd/github-runner/_work/_temp/7be025e4-95b0-4ccc-adeb-e955b6a9c69c
  ##[debug]destination /ssd/github-runner/_work/_tool/jf/[RELEASE]/x64
  ##[debug]destination file /ssd/github-runner/_work/_tool/jf/[RELEASE]/x64/jf
  ##[debug]finished caching tool
  ##[debug]Caching tool jfrog [RELEASE] x64
  ##[debug]source file: /ssd/github-runner/_work/_temp/7be025e4-95b0-4ccc-adeb-e955b6a9c69c
  ##[debug]destination /ssd/github-runner/_work/_tool/jfrog/[RELEASE]/x64
  ##[debug]destination file /ssd/github-runner/_work/_tool/jfrog/[RELEASE]/x64/jfrog
  ##[debug]finished caching tool
  /ssd/github-runner/_work/_tool/jf/[RELEASE]/x64/jf config add setup-jfrog-cli-server --url https://artifactory.company.com/ --interactive=false --overwrite=true --access-token ***
  15:10:13 [Warn] couldn't extract payload from Access Token.
  The provided access token is not a valid JWT, probably a reference token.
  Some package managers only support basic authentication which requires also a username.
  If you plan to work with one of those package managers, please provide a username.
  ::endgroup::
##[debug]Node Action run completed with exit code 0
##[debug]JFROG_CLI_ENV_EXCLUDE='*password*;*secret*;*key*;*token*;*auth*;JF_ARTIFACTORY_*;JF_ENV_*;JF_URL;JF_USER;JF_PASSWORD;JF_ACCESS_TOKEN'
##[debug]JFROG_CLI_OFFER_CONFIG='false'
##[debug]JFROG_CLI_BUILD_NUMBER='170'
##[debug]JFROG_CLI_BUILD_URL='https://github.company.com/One-BT-VS/attribute-extractor-cvflow/actions/runs/4484567'
##[debug]JFROG_CLI_USER_AGENT='setup-jfrog-cli-github-action/3.5.0'
##[debug]Finishing: Setup JFrog CLI


# Post Setup JFrog CLI

##[debug]Evaluating: secrets.TRS_ARTIFACTORY_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'TRS_ARTIFACTORY_TOKEN'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating condition for step: 'Post Setup JFrog CLI'
##[debug]Evaluating: always()
##[debug]Evaluating always:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Post Setup JFrog CLI
##[debug]Loading inputs
##[debug]Loading env
Post job cleanup.
::group::Cleanup JFrog CLI servers configuration
Cleanup JFrog CLI servers configuration
  Error: 'download-repository' input provided, but no JFrog environment details found. Hint - Ensure that the JFrog connection details environment variables are set: either a Config Token with a JF_ENV_ prefix or separate env config (JF_URL, JF_USER, JF_PASSWORD, JF_ACCESS_TOKEN)
  ::endgroup::
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Post Setup JFrog CLI

Workflow is more or less this:

env:
  JFROG_CLI_BUILD_NAME: ${{ github.event.repository.name }}

jobs:
  publish-to-artifactory:
    name: Publish artifacts to Artifactory
    needs: build-and-test
    runs-on: [self-hosted, Linux, Docker]

    steps:
      - name: Checkout project
        uses: actions/checkout@v3
        with:
          path: ${{ github.event.repository.name }}

      - name: Download artifacts (Debug)
        uses: actions/download-artifact@v3
        with:
          name: Build output (Debug)
          path: artifacts/Debug

      - name: Setup JFrog CLI
        uses: jfrog/setup-jfrog-cli@v3
        env:
          JF_URL: https://artifactory.company.com/
          JF_ACCESS_TOKEN: ${{ secrets.TRS_ARTIFACTORY_TOKEN }}
        with:
          version: latest
          download-repository: bt-vs-jfrog-cli-remote

      - name: Upload to Artifactory (Debug)
        run: |
          jf rt upload \
            bin/ \
            bt-vs-generic-dev-local/${{ env.JFROG_CLI_BUILD_NAME }}/${{ env.JFROG_CLI_BUILD_NAME }}-${{ needs.build-and-test.outputs.version }}-${{ env.JFROG_CLI_BUILD_NUMBER }}-Debug.zip \
            --module Debug \
            --archive=zip
        working-directory: artifacts/Debug

      - name: Publish build info
        run: |
          jf rt build-add-git
          jf rt build-publish --detailed-summary
        working-directory: ${{ github.event.repository.name }}

      - name: Add build info to workflow summary
        run: |
          echo '```' >> $GITHUB_STEP_SUMMARY
          jf rt search \
            --build ${{ env.JFROG_CLI_BUILD_NAME }}/${{ env.JFROG_CLI_BUILD_NUMBER }} >> $GITHUB_STEP_SUMMARY
          echo '```' >> $GITHUB_STEP_SUMMARY

@kingledion
Copy link
Author

@yahavi The new version is not fixing the error for us. The same "Post Setup JFrog CLI" step is failing as with @fschoenm's case.

Debug logs:

##[debug]Evaluating: env.ARTIFACTORY_USERNAME
##[debug]Evaluating Index:
##[debug]..Evaluating env:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'ARTIFACTORY_USERNAME'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating: env.ARTIFACTORY_ACCESS_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating env:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'ARTIFACTORY_ACCESS_TOKEN'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating condition for step: 'Post Setup JFrog CLI'
##[debug]Evaluating: always()
##[debug]Evaluating always:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Post Setup JFrog CLI
##[debug]Loading inputs
##[debug]Loading env
Post job cleanup.
::group::Cleanup JFrog CLI servers configuration
Cleanup JFrog CLI servers configuration
 Error: 'download-repository' input provided, but no JFrog environment details found. Hint - Ensure that the JFrog connection details environment variables are set: either a Config Token with a JF_ENV_ prefix or separate env config (JF_URL, JF_USER, JF_PASSWORD, JF_ACCESS_TOKEN)
 ::endgroup::
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Post Setup JFrog CLI

@kingledion
Copy link
Author

Looks like the problem is that the setup step never initializes JFrogCredentials.

At this point in the code you are looking for the credentials: https://github.com/jfrog/setup-jfrog-cli/blob/master/src/utils.ts#L393

It is called here with credentials passed through unchanged from the method argument: https://github.com/jfrog/setup-jfrog-cli/blob/master/src/utils.ts#L172

And initially called here by the cleanup function with an empty struct as argument: https://github.com/jfrog/setup-jfrog-cli/blob/master/src/cleanup.ts#L7

You need to add a step to get CLI credentials like this: https://github.com/jfrog/setup-jfrog-cli/blob/master/src/main.ts#L8

I'm on my phone and my work computer won't let me fork a non-enterprise repo, so I can't push a PR until this evening.

@sverdlov93
Copy link
Contributor

Hi @kingledion and @fschoenm ,
now that we know that the issue is on the Post install section we found the issue. We will release a fix soon!

@yahavi
Copy link
Member

yahavi commented Jan 18, 2024

@kingledion @fschoenm,
Setup JFrog CLI v3.5.2 has been released, addressing the mentioned issue. Feel free to give it a go, and your feedback would be greatly appreciated.

@kingledion
Copy link
Author

Yes, confirmed working. Thanks for the fix.

@fschoenm
Copy link

Also works for us, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants