github packages: peer not authenticated - jenkins

I have gradle configuration for github packages similar to this:
repositories {
mavenCentral()
maven {
name = 'GitHubPackages'
url = uri('https://maven.pkg.github.com/whatever/whatever')
credentials {
username = System.getenv("GITHUB_PKG_USER")
password = System.getenv("GITHUB_PKG_TOKEN")
}
}
}
And some library which I read from that repo. I've noticed our jenkins build sometimes failed with:
> Could not resolve all files for configuration ':compileClasspath'.
> Could not download library-name.jar
> Could not get resource 'https://maven.pkg.github.com/correct-path-to-jar.jar'.
> Could not GET 'https://github-registry-files.githubusercontent.com/275167411/e47ffc80-8d5d-11eb-81c7-80fd7fa422bd?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA52GIFG5T%2F20210330%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210330T154314Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=67765f831023f46bf93d2a9354e2cd38913d87481281975dadd7e7d26a63b953'.
> peer not authenticated
And then after rebuild it just works. Linked xml looks this way:
<Error>
<Code>AccessDenied</Code>
<Message>Request has expired</Message>
<X-Amz-Expires>300</X-Amz-Expires>
<Expires>2021-03-30T15:48:14Z</Expires>
<ServerTime>2021-03-31T10:31:25Z</ServerTime>
<RequestId>D2AF221VHNYTPTA3</RequestId>
<HostId>JEzBk1i9ZfzhyU3ab7TMtHozZ5l6BQvjPD+BzWlbMJEToTgC1UuGeMUMoBtUSjnvu3mlpkTDN9s=</HostId>
</Error>
Any ideas what is it about ?
gradle - 6.6.1
java - 11

In my case I was receiving the same error with maven and openjdk-11 when running in Travis-CI. The error does not happen when running with oracle jdk 8, so I ended up switching to run maven with oracle jdk 8. It might be a side-effect of JDK switcher in travis CI, or something else.

Related

Jenkins, Gradle : How to publish Dependency report to Sonar Dashboard

Currently we're using Jenkins free style job for Gradle project and using following commands to run Sonar and Dependencycheck
./gradlew clean build sonarqube dependencyCheckAnalyze \
and I'm getting following message
Analyzing /opt/jenkins_slave_home/workspace/AA/package-lock.json - however, the node_modules directory does not exist. Please run npm install prior to running dependency-check
Generating report for project AA_ArbitraryBuild
Found 0 vulnerabilities in project AA
and we can able to see a file inside "ws/build/reports/" but it dint scanned anything.
Following are the "build.gardle" file
buildscript {
repositories {
maven { url artifactoryRepoUrl }
mavenCentral()
}
dependencies {
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7'
classpath 'org.owasp:dependency-check-gradle:6.0.3'
}
}
apply plugin: 'org.sonarqube'
apply plugin: 'org.owasp.dependencycheck'
sonarqube {
properties {
property 'sonar.projectName', sonarProjectName
property 'sonar.projectKey', sonarProjectKey
property 'sonar.host.url', sonarHostUrl
property 'sonar.login', sonarAuthToken
property 'sonar.dependencyCheck.reportPath', sonarDependencyCheckReport
property 'sonar.dependencyCheck.htmlReportPath', sonarDependencyCheckHTMLReport
}
}
Can you plz help on what are the additional steps that I need to add.
You've got all you need to push result to sonar. Make sure that you provide right path for your owasp vulnerabilities report for sonar plugin. It's sonar.dependencyCheck.reportPath and should point to build/reports directroy, and if you produce html report file you can point it with sonar.dependencyCheck.htmlReportPath.

How to publish a WAR file to maven (Nexus) repository with Jenkins via Gradle task

I'm struggling with deploying the war file to Nexus repository using Jenkinsfile via Gradle task.
The war is being created successfully. I have also no problem with deploying JARs (since there are examples everywhere how to do it).
So I have this publishing section in my build.grade:
publishing {
repositories {
maven {
URI releasesUrl = new URI("${UploadURL}/repository/releases")
URI snapshotsUrl = new URI("${UploadURL}/repository/snapshots")
afterEvaluate {
url version.endsWith("SNAPSHOT") ? snapshotsUrl : releasesUrl
}
credentials {
username "${user}"
password "${password}"
}
}
}
publications {
mavenWeb(MavenPublication) {
from components.web
artifact war.archivePath
}
}
}
With pluggins:
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
The URL for repositories is also specified in the build script correctly (test publish with the jar works just fine)
And the Jenkinsfile:
stage ('Publish war') {
steps {
sh "sh gradlew publish"
}
}
Currently I'm getting this error from jenkins build:
Task :publishMavenWebPublicationToMavenRepository FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':publishMavenWebPublicationToMavenRepository'.
Failed to publish publication 'mavenWeb' to repository 'maven'
Invalid publication 'mavenWeb': multiple artifacts with the identical extension and classifier ('war', 'null').
I'm quite sure that the problem is within "publications" part of Gradle task.
For publishing the Jars I have been using it like this:
[...]
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar
}
}
[...]
task sourceJar(type: Jar) {
classifier 'sources'
from sourceSets.main.java
}
I do not know how to configure from, artifact and classifier for this task. I do not even know if all of these parameters should be configured... Could anyone help me with that?
It turned out, that the origin of the problem was this section:
afterEvaluate {
url version.endsWith("SNAPSHOT") ? snapshotsUrl : releasesUrl
}
This feature works with Gradle 5.X version however, I was using Gradle 4.8. That lead to null instead of propper url value...
Unfortunately, it took a while since the exception message does not suggest where the problem was.

Grails 3 Cookie plugin not found

I want to use the Grails 3 Cookie plugin (http://plugins.grails.org/plugin/ctoestreich/cookie). In my build.gradle I have these entries here:
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
mavenCentral()
}
dependencies {
[...]
compile 'org.grails.plugins:grails-cookie:2.0.5'
[...]
}
But when running gradle build, he's got problems looking up that dependency:
> Could not resolve all dependencies for configuration ':runtime'.
> Could not find org.grails.plugins:grails-cookie:2.0.5.
Searched in the following locations:
file:/home/marp/.m2/repository/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.pom
file:/home/marp/.m2/repository/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.jar
https://repo.grails.org/grails/core/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.pom
https://repo.grails.org/grails/core/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.jar
https://repo1.maven.org/maven2/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.pom
https://repo1.maven.org/maven2/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.jar
Required by:
project :
Do I need to include an other maven repo? Or is the plugin just gone?
Instead compile 'org.grails.plugins:grails-cookie:2.0.5'
use compile 'org.grails.plugins:cookie:2.0.5'
also you can set cookie expiration configuration in application.yml file
Example-grails.plugins.cookie.cookieage.default: 43200
repo of dependency
Hope it helps you
According to this (at the time of writing), 2.0.3 appears to be the newest version on the repo.grails.org repo:
http://repo.grails.org/grails/core/org/grails/plugins/grails-cookie/
change your dependency to:
compile 'org.grails.plugins:cookie:2.0.3'

Jenkins searches in wrong artifactory path and build fails but local build is successful

we do have a Jenkins server and an Artifactory repository. We have published several libraries to that artifactory repo and it works well. We have also published the anyline sdk as an aar-module. In our projects we reference the artifactory-repo and the aar-module as such:
dependencies { ... compile 'anyline:anyline:3.6.1#aar' ... }
repositories {
jcenter()
mavenLocal()
// External Third Party Libs lookup
maven {
url "https://MYURL/artifactory/libs-snapshot-local"
credentials {
username = bla
password = blubb
}
}
// External Third Party Libs lookup
maven {
url "https://MYURL/artifactory/libs-release-local"
credentials {
username = bla
password = blubb
}
}
// External Third Party Libs lookup
maven {
url "https://MYURL/artifactory/ext-release-local"
credentials {
username = bla
password = blubb
}
}
}
The url for the aar-package is this:
https://MYURL/artifactory/ext-release-local/anyline/anyline/3.6.1/anyline-3.6.1.aar
Locally the build just runs fine but on the jenkins it throws the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':BLABLUBB_app'.
> Could not find anyline.jar (anyline:anyline:3.6.1).
Searched in the following locations:
https://MYURL/artifactory/libs-release-local/anyline/anyline/3.6.1/anyline-3.6.1.jar
Now there are two weird things going on here:
1.) Why does the jenkins-build look up a jar-file? Isn't it supposed to look up an aar-file or am I missing something?
2.) The server seems to search in the wrong folder. It should also search in
ext-release-local
and not only in
libs-release-local where obviously no anyline-lib is located.
Does anyone have a hint on whats going wrong here?
The build script on the server is the same as the local one of course, the local repo and the server point to the same git.
Help appreciated,
Thanks
Daniel Sahm

How does Jenkins Artifactory Plugin communicates resolver credentials to Gradle?

Using the Jenkins Artifactory Plugin and Gradle, I am able to deploy to my Artifactory instance successfully. However, I have not been able to use the credentials entered into Jenkins configuration to resolve the artifact from the same repository.
Here is the build.gradle, adopted right from Artifactory's "Generate Build Script" feature in Artifactory.
apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
buildscript {
repositories {
maven {
url 'http://artifactory.myorg.com:8081/artifactory/plugins-release'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
//Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.3"
}
}
allprojects {
apply plugin: "com.jfrog.artifactory"
}
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'libs-release'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
dependencies {
compile group: "com.myorg", name: "internal-library", version: '1.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Job configuration on Jenkins:
Jenkins Artifactory plugin configuration:
Error:
FAILURE: Build failed with an exception.
* Where:
Build file '/var/lib/jenkins/jobs/deleteme/workspace/build.gradle' line: 10
* What went wrong:
A problem occurred evaluating root project 'untitled2'.
> Could not find property 'artifactory_user' on Credentials [username: null].
Locally, resolving artifacts works (artifactory_user etc are resolved, because I configured them in my local ~/.gradle/gradle.properties). However, builds fail, because artifactory_user is not defined. Of course, I can configure a gradle.properties for Jenkins to use (and this works), however how is this supposed to work? It appears the Jenkins Artifactory Plugin Gradle integration is supposed to somehow communicate resolver credentials. Is there a way to do this without replicating the credentials in two places on Jenkins?
tl;dr username = "${project.getProperty('artifactory.publish.username')}"
Note: I haven't tested this on a Jenkins machine yet
The Jenkins artifactory plugin's gradle integration appears to do two things
Inject the artifactory configuration using a [gradle init script]
Provide build and artifactory configuration information
Both involve writing files to a temporary folder (i.e. /tmp on linux). If you have access to your build server you will probably have a lot of buildInfo\d{19}.properties and init-artifactory\d{19}gradle files in your temp folder.
Looking inside one of these buildInfo files reveals the resolve and publish credentials are stored in artifactory.resolve.username and artifactory.publish.username, respectively.
Trying to setting and trying to use ${artifactory.publish.username} directly doesn't work on my local machine; I assume it has to do with gradle trying to access the property before it is set. But the project.getProperty method works.
buildscript {
repositories {
maven {
url 'http://artifactory.myorg.com:8081/artifactory/plugins-release'
credentials {
username = "${project.getProperty('artifactory.resolve.username')}"
password = "${project.getProperty('artifactory.resolve.password')}"
}
}
}
}
artifactory {
publish {
contextUrl = "${project.getProperty('artifactory.publish.contextUrl')}"
repository {
repoKey = 'libs-release-local'
username = "${project.getProperty('artifactory.publish.username')}"
password = "${project.getProperty('artifactory.publish.password')}"
maven = true
}
}
resolve {
repository {
contextUrl = "${project.getProperty('artifactory.resolve.contextUrl')}"
repoKey = 'libs-release'
username = "${project.getProperty('artifactory.resolve.username')}"
password = "${project.getProperty('artifactory.resolve.password')}"
maven = true
}
}
}
You will have to update your local ~/.gradle/gradle.properties accordingly
artifactory.publish.contextUrl=<artifactory-url>
artifactory.publish.username=<username>
artifactory.publish.password=<password>
artifactory.resolve.contextUrl=<artifactory-url>
artifactory.resolve.username=<username>
artifactory.resolve.password=<password>
I am also banging my head against the wall with this one...I tried all the combinations myself and the only one that seems to be working is adding the gradle.properties to the jenkins server.
Finally I ended up not using the artifactory gradle plugin from jenkins alltogether.R ather add it to the build.gradle and simply call artifactoryPublish from Jenkins Server gradle plugin.

Resources