jenkinsci / jenkinsci/jfrog-plugin
jf gradle - calls do not work with gradlew
- Dominant language
- Java
- Stars
- 16
- Forks
- 85
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
When calling `jf "gradle "` 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:

### 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_
Contributor guide
Research direction
Start at the `jf gradle` entry point and trace the invocation of `./gradlew --version` under Jenkins, using the reported Jenkins 2.414.1, plugin 1.5.0, and CLI 2.48.0 versions. Reproduce the failure with the supplied pipeline and compare it with direct shell execution; done means the Gradle wrapper runs successfully through the plugin and the reported version error is resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, ci-cd
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100