sonatype-nexus-community / scan-gradle-plugin

Gradle plugin that scans the dependencies of a Gradle project using Sonatype platforms: OSS Index and Nexus IQ Server.
Apache License 2.0
77 stars 21 forks source link

[BUG] Unable to use the project propertise #90

Closed puash closed 3 years ago

puash commented 3 years ago

Describe the bug Not able to use the project properties (-P arguments) or environment variables (-D arguments or injected from a tool) for nexusIQScan plugin.

Error logs:

2021-06-22T04:36:53.578+0000 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :nexusIQScan FAILED 2021-06-22T04:36:53.578+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Task :nexusIQScan' started 2021-06-22T04:36:53.578+0000 [INFO] [com.android.build.gradle.internal.profile.RecordingBuildListener] Task :nexusIQScan in app_bt Starting 2021-06-22T04:36:53.581+0000 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter] Putting task artifact state for task ':nexusIQScan' into context took 0.0 secs. 2021-06-22T04:36:53.581+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Snapshot task inputs for :nexusIQScan' started 2021-06-22T04:36:53.582+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Snapshot task inputs for :nexusIQScan' 2021-06-22T04:36:53.582+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Snapshot task inputs for :nexusIQScan' completed 2021-06-22T04:36:53.582+0000 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter] Removed task artifact state for task ':nexusIQScan' from context. 2021-06-22T04:36:53.582+0000 [INFO] [com.android.build.gradle.internal.profile.RecordingBuildListener] Task :nexusIQScan in app_bt Finished 2021-06-22T04:36:53.593+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Task :nexusIQScan' 2021-06-22T04:36:53.593+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Task :nexusIQScan' completed 2021-06-22T04:36:53.593+0000 [INFO] [org.gradle.execution.plan.DefaultPlanExecutor] :nexusIQScan (Thread[Execution worker for ':',5,main]) completed. Took 0.017 secs. 2021-06-22T04:36:53.593+0000 [DEBUG] [org.gradle.execution.plan.DefaultExecutionPlan] Node :nexusIQScan failed 2021-06-22T04:36:53.593+0000 [DEBUG] [org.gradle.execution.plan.DefaultExecutionPlan] Node :nexusIQScan completed, executed: true 2021-06-22T04:36:53.593+0000 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Execution worker for ':': released lock on : 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.20 completed (1 worker(s) in use) 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Execution worker for ':': released lock on root.1.20 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':',5,main]] finished, busy: 0.017 secs, idle: 0.002 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 11,5,main]] finished, busy: 0.0 secs, idle: 0.017 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 9,5,main]] finished, busy: 0.0 secs, idle: 0.017 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 10,5,main]] finished, busy: 0.0 secs, idle: 0.017 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 2,5,main]] finished, busy: 0.0 secs, idle: 0.019 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Daemon worker,5,main]] finished, busy: 0.0 secs, idle: 0.017 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 4,5,main]] finished, busy: 0.0 secs, idle: 0.018 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 3,5,main]] finished, busy: 0.0 secs, idle: 0.019 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 5,5,main]] finished, busy: 0.0 secs, idle: 0.018 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 6,5,main]] finished, busy: 0.0 secs, idle: 0.018 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 7,5,main]] finished, busy: 0.0 secs, idle: 0.018 secs 2021-06-22T04:36:53.594+0000 [DEBUG] [org.gradle.execution.plan.DefaultPlanExecutor] Execution worker [Thread[Execution worker for ':' Thread 8,5,main]] finished, busy: 0.0 secs, idle: 0.017 secs 2021-06-22T04:36:53.598+0000 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskExecutionGraph] Timing: Executing the DAG took 0.025 secs 2021-06-22T04:36:53.601+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Run tasks' 2021-06-22T04:36:53.601+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Run tasks' completed 2021-06-22T04:36:53.629+0000 [DEBUG] [org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService] Executing [class org.jetbrains.kotlin.gradle.plugin.statistics.DefaultKotlinBuildStatsService.buildFinished] . . . 2021-06-22T04:36:53.673+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2021-06-22T04:36:53.673+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 2021-06-22T04:36:53.673+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2021-06-22T04:36:53.673+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 2021-06-22T04:36:53.674+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Some problems were found with the configuration of task ':nexusIQScan' (type 'NexusIqScanTask'). 2021-06-22T04:36:53.674+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > No value has been specified for property 'applicationId'. 2021-06-22T04:36:53.674+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > No value has been specified for property 'password'. 2021-06-22T04:36:53.674+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > No value has been specified for property 'serverUrl'. 2021-06-22T04:36:53.674+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > No value has been specified for property 'stage'. 2021-06-22T04:36:53.674+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > No value has been specified for property 'username'. 2021-06-22T04:36:53.674+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]

To Reproduce Steps to reproduce the behaviour: My project has 2 gradle.build (one parent and one child)

  1. Apply the latest plugin in gradle.build (parent)

plugins { id "org.sonatype.gradle.plugins.scan" version "2.0.11" }

  1. using project properties for the credentials:

//Sonatype Nexus Configuration nexusIQScan { username = project['username'] password = project['password'] serverUrl = project['serverUrl'] applicationId = project['appID'] stage = project['stage'] }

  1. Run the command in the jenkins pipeline script

./gradlew nexusIQScan -Pusername=admin -Ppassword=pass -PserverUrl=http://localhost:8080 -PappID=app1 -Pstage=build

OR

  1. using project properties for the credentials:

//Sonatype Nexus Configuration nexusIQScan { username = System.getenv('username') password = System.getenv('password') serverUrl = System.getenv('serverUrl') applicationId = System.getenv('appID') stage = System.getenv('stage') // build is used if omitted allConfigurations = true // if true includes the dependencies in all resolvable configurations. By default is false, meaning only 'compileClasspath' and 'releaseCompileClasspath' are considered resultFilePath = 'results.json' // Optional. JSON file containing results of the evaluation }

  1. Run the command in the jenkins pipeline script

./gradlew nexusIQScan -Dusername=admin -Dpassword=pass -DserverUrl=http://localhost:8080 -DappID=app1 -Dstage=build

Expected behavior Able to run the nexusIQ scan without any issues

Desktop (please complete the following information):

guillermo-varela commented 3 years ago

Hi @puash,

First of all, I apologize for taking so long answering this. Somehow I though I already replied.

There is an example showing a Jenkins configuration at https://github.com/guillermo-varela/example-scan-gradle-plugin#nexus-iq-server-1

Credentials in that example are stored in the credentials configuration in Jenkins. There are links there expanding more on that topic.

Could you please give it a try and see if that works in your Jenkins instance (rather than passing the values as parameters)?

guillermo-varela commented 3 years ago

Hi @puash,

I was able to get another round to look at this and found an issue with our documentation regarding environment variables.

It turns out the -D flag doesn't set environment variables but instead it's for system properties so I updated the readme file to specify how that can be used: https://github.com/sonatype-nexus-community/scan-gradle-plugin#sensitive-data

Testing the plugin in a local Jenkins instances I got this working:

Using project properties

nexusIQScan {
  username = project['username']
  password = project['password']
  serverUrl = project['serverUrl']
  applicationId = project['appID']
  stage = project['stage']
}
pipeline {
  agent any
  tools {
    jdk 'OpenJDK 8'
  }
  stages {
    stage('Nexus IQ Scan') {
      steps {
        sh './gradlew nexusIQScan -Pusername=admin -Ppassword=passw -PserverUrl=http://localhost:8070 -PappID=app1 -Pstage=build'
      }
    }
  }
}

Using system properties

nexusIQScan {
  username = System.properties['username']
  password = System.properties['password']
  serverUrl = System.properties['serverUrl']
  applicationId = System.properties['appID']
  stage = System.properties['stage']
}
pipeline {
  agent any
  tools {
    jdk 'OpenJDK 8'
  }
  stages {
    stage('Nexus IQ Scan') {
      steps {
        sh './gradlew nexusIQScan -Dusername=admin -Dpassword=admin123 -DserverUrl=http://localhost:8070 -DappID=app1 -Dstage=build'
      }
    }
  }
}

Using the Jenkins credentials store

nexusIQScan {
  username = System.getenv('IQ_CREDENTIALS_USR')
  password = System.getenv('IQ_CREDENTIALS_PSW')
  serverUrl = 'http://localhost:8070'
  applicationId = 'app1'
}
pipeline {
  agent any
  tools {
    jdk 'OpenJDK 8'
  }
  stages {
    stage('Nexus IQ Scan') {
      environment {
        IQ_CREDENTIALS = credentials('iq.credentials')
      }
      steps {
        sh './gradlew nexusIQScan'
      }
    }
  }
}

Thank you for bringing this to our attention, it allowed us to understand better how to pass parameters to our plugin and hopefully other users find our updated documentations easier to follow :)

guillermo-varela commented 3 years ago

Closing due to inactivity. If the issue continues, feel free to open a new issue.