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

jf gradle - calls do not work with gradlew #24

Open
8L4ckc0FF33 opened this issue Sep 20, 2023 · 1 comment
Open

jf gradle - calls do not work with gradlew #24

8L4ckc0FF33 opened this issue Sep 20, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@8L4ckc0FF33
Copy link

Describe the bug

When calling jf "gradle <something>" in a Jenkins pipeline, with --use-wrapper=true it fails with an 'unexpected error'

jf gradle clean artifactoryPublish
18:01:47 [Info] Running gradle...
18:01:47 [Info] Running gradle command: ./gradlew --version
18:01:47 [Error] unexpected error occurred during attempt to get the Gradle version: NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED

We assume that the jfrog-plugin does not find java, although the environment variable is set and it can be called by shell within the step.

Current behavior

Our script:

script {
    dir('/opt/xxx/data/jenkins/workspace/Test-JF/xray-demo') {
        withEnv(["JAVA_HOME=/opt/xxx/jdk11.0.11_9"]) {
            env.JAVA_HOME = '/opt/xxx/jdk11.0.11_9'
            env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
            sh "env" //shows correct JAVA_HOME and PATH
            sh "java --version" //executes
            sh "cp /opt/xxx/bin/jf ." //to make sure the context is right. but doesn't change anything
            sh "chmod +x ./jf"
            sh "ls -al"
            sh "./jf c add xxx-artifactory --user=srvGIT-SELECT --url=https://repo.xxx.local --artifactory-url=https://repo.xxx.local/artifactory --distribution-url=https://repo.xxx.local/distribution --xray-url=https://repo.xxx.local/xray --interactive=false --overwrite=true"
           sh "./jf gradle-config --use-wrapper=true --repo-resolve=xxx.maven.release --repo-deploy=xy.maven.staging.local --global --uses-plugin"
           def retVal = sh(script: """./jf gradle --build-name="test" --build-number="0.0.1" """, returnStdout: true)
           echo retVal
        }                         
    }
}

Which leads to output (shortend):

Started by user
Running on [Jenkins](https://jenkins:11001/jenkins/computer/(built-in)/) in /opt/xxx/data/jenkins/workspace/Test-JF
Running in /opt/xxx/data/jenkins/workspace/Test-JF/xray-demo
+ env
JAVA_HOME=/opt/xxx/jdk11.0.11_9
PATH=/opt/xxx/jdk11.0.11_9/bin:...
+ java --version
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL- 
UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED -- 
add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)
+ cp /opt/xxx/bin/jf .
+ chmod +x ./jf
+ ls -al
drwxr-x--- 8 xxx yyy      256 20. Sep 22:50 .
drwxr-x--- 4 xxx yyy       44 20. Sep 12:47 ..
-rw-r----- 1 xxx yyy     2371 20. Sep 12:45 build.gradle
drwxr-x--- 8 xxx yyy      163 20. Sep 12:45 .git
-rw-r----- 1 xxx yyy      444 20. Sep 12:45 .gitignore
drwxr-xr-x 4 xxx yyy       32 20. Sep 14:54 .gradle
drwxr-x--- 3 xxx yyy       21 20. Sep 12:45 gradle
-rw-r----- 1 xxx yyy      402 20. Sep 12:45 gradle.properties
-rwxr-x--- 1 xxx yyy     8188 20. Sep 12:45 gradlew
-rw-r----- 1 xxx yyy     2747 20. Sep 12:45 gradlew.bat
-rw-r----- 1 xxx yyy     6473 20. Sep 12:45 Jenkinsfile
-rwxr-x--- 1 xxx yyy 26718552 20. Sep 23:02 jf
drwxr-x--- 3 xxx yyy       22 20. Sep 12:54 .jfrog
drwxr-x--- 2 xxx yyy      102 20. Sep 12:45 kubernetes
-rw-r----- 1 xxx yyy       81 20. Sep 12:45 README.md
-rw-r----- 1 xxx yyy       32 20. Sep 12:45 settings.gradle
drwxr-x--- 4 xxx yyy       30 20. Sep 12:45 src
+ ./jf c add xxx-artifactory --user=abc --url=https://repo.xxx.local/ --artifactory-url=https://repo.xxx.local/artifactory --distribution-url=https://repo.xxx.local/distribution --xray-url=https://repo.xxx.local/xray --interactive=false --overwrite=true
+ ./jf gradle-config --use-wrapper=true --repo-resolve=xxx.maven.release --repo-deploy=xy.maven.staging.local --global --uses-plugin
23:02:28 [Info] gradle build config successfully created.
+ ./jf gradle --build-name=test --build-number=0.0.1
23:22:32 [Debug] JFrog CLI version: 2.48.0
23:22:32 [Debug] OS/Arch: linux/amd64
23:22:32 [Debug] Usage Report: Sending info...
23:22:32 [Debug] Saving build general details at: /tmp/jfrog/builds/4eace77046a199e189022686bbd1f9c85369165d41c55781ea4f28c7f58bd095/partials
23:22:32 [Info] Running gradle...
23:22:32 [Info] Running gradle command: ./gradlew --version
23:22:32 [Debug] Sending HTTP GET request to: https://repo.xxx.local/artifactory/api/system/version
23:22:32 [Debug] Artifactory response: 200 OK
23:22:32 [Debug] JFrog Artifactory version is: 7.63.14
23:22:32 [Debug] Sending HTTP POST request to: https://repo.xxx.local/artifactory/api/system/usage
23:02:28 [Info] Running gradle...
23:02:28 [Info] Running gradle command: ./gradlew --version
23:22:32 [Error] unexpected error occurred during attempt to get the Gradle version: NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED    ERROR: script returned exit code 1
/opt/xxx/data/jenkins/workspace/Test-JF@tmp/jfrog/124/.jfrog deleted
Finished: FAILURE

The weird thing is: Calling all these steps from the bash on the hosting machine it works:

image

Reproduction steps

Jenkins: Version 2.414.1

We followed this description: https://plugins.jenkins.io/jfrog/#plugin-content-configuring-jfrog-cli-as-a-tool

  • Installing the plugin
  • Configuring the plugin
  • Setting the path to jfrog cli executable to /opt/xxx/bin/ and call it xxx-artifactory
  • Setting the tool
  • Checking jf by calling jf "dl ..." which downloaded the desired file - works!
  • And then trying the script above
  • We also tried sh "jf ..." and sh(script: "jf gradle...", returnStdout: true)
  • We checked permissions and ownership of files & folders.
  • We copied the jf-cli locally

Expected behavior

Executing the gradle-wrapper from within the plugin.

JFrog plugin version

1.5.0

JFrog CLI version

2.48.0

Operating system type and version

Linux

JFrog Artifactory version

No response

JFrog Xray version

No response

@8L4ckc0FF33 8L4ckc0FF33 added the bug Something isn't working label Sep 20, 2023
@8L4ckc0FF33
Copy link
Author

We managed to get it running, by unsetting JDK_JAVA_OPTIONS before making any jf-call:

...
sh "unset JDK_JAVA_OPTIONS && ./jf c add xxx-artifactory --user=srvGIT-SELECT --url=https://repo.xxx.local --artifactory-url=https://repo.xxx.local/artifactory --distribution-url=https://repo.xxx.local/distribution --xray-url=https://repo.xxx.local/xray --interactive=false --overwrite=true"
sh "./jf gradle-config --use-wrapper=true --repo-resolve=xxx.maven.release --repo-deploy=xy.maven.staging.local --global --uses-plugin"
def retVal = sh(script: """unset JDK_JAVA_OPTIONS && ./jf gradle --build-name="test" --build-number="0.0.1" """, returnStdout: true)
echo retVal
...

JDK_JAVA_OPTIONS:

JDK_JAVA_OPTIONS= --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED

An explanation would be very helpful. We don't have any...

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

No branches or pull requests

1 participant