gradle jib cannot authenticate against ghcr in GitHub workflow - gradle

This is somehow strange: I can build and push m ycontainer image with gradle jib to my github container registry (ghcr) locally but not in a github worflow. Even more strange is, that as soon as the git workflow fails, the local jib fails with the same error. To make it work at least locally again, I have to create a new github token.
Steps to reproduce:
My build.gradle
plugins {
id 'java'
id 'idea'
id 'org.springframework.boot' version '3.0.1'
id 'com.google.cloud.tools.jib' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.0'
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
configurations {
published
compileOnly {
extendsFrom annotationProcessor
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
annotationProcessor 'org.springframework.boot:spring-boot-configuration- processor'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation('org.assertj:assertj-core')
testImplementation('org.junit.jupiter:junit-jupiter-api')
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine')
}
tasks.withType(Test) {
useJUnitPlatform()
}
task prepareKotlinBuildScriptModel {
}
springBoot {
buildInfo()
}
bootJar {
enabled = false
}
jar {
enabled = true
}
def baseImage = 'ghcr.io/tobias-neubert/eclipse-temurin:17.0.2_8-jre'
jib {
from {
image = baseImage
auth {
username = "tobias-neubert"
password = "${System.getenv("GITHUB_PASSWORD")}"
}
}
to {
image = 'ghcr.io/tobias-neubert/motd-service'
auth {
username = "tobias-neubert"
password = "${System.getenv("GITHUB_PASSWORD")}"
}
}
container {
mainClass = 'com.neubert.scaffold.motdservice.MotdServiceApplication'
ports = ['8080']
}
}
Create a new personal access token in github.
Execute locally GITHUB_PASSWORD=<personal-access-token> ./gradlew :motd-service:jib
The image is built and pushed successfully to the ghcr, where I can see it. You execute a local build repeatedly, it will succeed.
My github workflow:
name: Build and push motd-service
on:
push:
branches:
- actions
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout#v3
- name: Set up Java
uses: actions/setup-java#v2
with:
java-version: 17
distribution: temurin
- name: Setup Gradle
uses: gradle/gradle-build-action#v2
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build the motd image
run: |
GITHUB_PASSWORD=<personal-access-token> ./gradlew :motd-service:jib
The job fails with:
Execution failed for task ':motd-service:jib'.
> com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: Build image failed, perhaps you should make sure you have permissions for ghcr.io/tobias-neubert/eclipse-temurin and set correct credentials. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-forbidden-or-denied for help
Execute GITHUB_PASSWORD=<personal-access-token> ./gradlew :motd-service:jib locally again, and it fails with the same error.
I must miss something important here. Can you tell me what?

I found it: I am using the GITHUB_TOKEN now for accessing the GHCR. I tried that before but I did not realize that
you have to set the write permission in your workflow for that token and
you give the repository of your workflow permission to write into the desired package and to read the desired base package.
So with this workflow and the write permission in the package settings for my repository it works:
name: Build and push motd-service
on:
push:
branches:
- actions
permissions:
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout#v3
- name: Set up Java
uses: actions/setup-java#v2
with:
java-version: 17
distribution: temurin
- name: Setup Gradle
uses: gradle/gradle-build-action#v2
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build the motd image
env:
GH_PASSWORD: '${{ secrets.GITHUB_TOKEN }}'
run: "./gradlew jib"

Related

Received status code 409 from server: Conflict error while migrating spring boot app to Gradle 7.3.3

I am moving my spring boot application from Gradle 5.3 to Gradle 7.3.3. I have mad the changes in the build.gradle accordingly as below:
It's just a snippet
buildscript {
ext {
springBootVersion = '2.2.7.RELEASE'
set('springCloudVersion', "Hoxton.SR6")
log4jVersion = '2.17.0'
}
repositories {
jcenter {
url "https://jcenter.bintray.com/"
}
maven {
url "https://artifactory.build.xxx.com"
credentials {
username = user
password = pwd
}
}
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
implementation(group: 'com.xxx.ym', name: 'external-service', version: '0.1.11', classifier: 'clientApi')
implementation(group: 'com.xxx.ym', name: 'conformance-service', version: '1.0.2', classifier: 'clientApi')
implementation(group: 'com.xxx.ym', name: 'security-service', version: '0.1.17', classifier: 'clientApi')
implementation(group: 'com.xxx.ym', name: 'product-service', version: '1.2.0-9.0-development', classifier: 'clientApi')
implementation(group: 'com.xxx.ym', name: 'service-client', version: '0.7.2')
implementation(group: 'com.xxx.ym', name: 'reasons-service', version: '0.7.1')
implementation('org.springframework.boot:spring-boot-starter-hateoas')
implementation('org.springframework.boot:spring-boot-starter-security')
}
}
When I try to do a clean build using gradlew clean build --refresh-dependencies I am always getting Could not GET 'https://artifactory.build.ym.com/XXXX-SNAPSHOT/com/xxx/ym/external-service/0.1.11/external-service-0.1.11.pom'. Received status code 409 from server: Conflict error for dependencies which are present in our own artifactory. With Gradle 5.3 the build was succeeding without any errors.
Could you please confirm if you are observing a similar pattern of error in Artifactory as below while reproducing this issue (artifactory.log (or) artifactory-service.log)?
Sending HTTP error code 409: The repository 'REPOSITORY_NAME' rejected the resolution of an artifact 'REPOSITORY_NAME:FILE_PATH' due to conflict in the snapshot release handling policy
If yes, then it appears to be the conflict between the request sent from the client and the type of request handled by the repository. Consider checking "Handle Releases" and "Handle Snapshots" checkboxes under the concerned Artifactory's respiratory settings. This should help to resolve this issue.

Pipeline Task Report Generator fails

I'm trying to create a test coverage report in Azure DevOps pipelines but I get The report file "path" is invalid. File does not exist.
Before I run this failing task, I run a task to execute the tests, and I see that task runTestsWithJacoco, defined in the build.gradle to create a Jacoco report is SKIPPED.
I'm using gradle 7.0.1 and jacoco version 0.8.7.
The gradle buil for project:
buildscript {
ext.jacoco_version = "0.8.7"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.1"
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
}
}
apply plugin: PropertiesPlugin
allprojects {
repositories {
google()
mavenCentral()
}
}
The gradle.build for app
plugins {
id 'jacoco'
}
jacoco {
toolVersion = jacoco_version
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
android {
testOptions {
unitTests.all {
useJUnitPlatform()
}
unitTests {
includeAndroidResources = true
}
}
}
task runTestsWithJacoco(
type: JacocoReport,
dependsOn: ['testDebugUnitTest'],
group: 'Reporting',
description: 'Running my tests with jacoco'
) {
def coverageSourceDirs = [
"src/main/java"
]
def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/Manifest*.*'
]
def javaClasses = fileTree(
dir: buildDir,
includes: ['intermediates/javac/debug/classes/**'],
excludes: fileFilter
)
classDirectories.from(files([ javaClasses ]))
additionalSourceDirs.from(files(coverageSourceDirs))
sourceDirectories.from(files(coverageSourceDirs))
executionData.from(fileTree(dir: buildDir, includes: [
"jacoco/testDebugUnitTest.exec"
]))
reports {
xml.enabled = true
html.enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
The pipeline:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Gradle#2
name: run_unit_tests
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: true
testResultsFiles: 'app/build/test-results/testDebugUnitTest/TEST-*.xml'
tasks: ':app:runTestsWithJacoco'
- task: reportgenerator#4
name: generate_report
inputs:
reports: 'app/build/reports/jacoco/runTestsWithJacoco/runUnitTestsWithCoverage.xml'
targetdir: 'coverage'
sourcedirs: 'service/src/main/java'
reporttypes: 'Badges;HtmlInline_AzurePipelines;Cobertura'
Why does reportgenerator#4 fail?
I appreciate any help.
I can reproduce the same issue in reportgenerator#4 task.
The root cause of this issue can be that the publishing path you set is invalid.
You can check the build log in Gradle task and check if you can see the following log record:
To solve this issue, you can try the following sample:
- task: Gradle#2
name: run_unit_tests
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: ':app:runTestsWithJacoco'
- task: reportgenerator#4
name: generate_report
inputs:
reports: '$(build.sourcesdirectory)/build/test-results/TEST-*.xml'
targetdir: 'coverage'
sourcedirs: 'service/src/main/java'
reporttypes: 'Badges;HtmlInline_AzurePipelines;Cobertura'
Result:
I ended up changing the build agent from Ubuntu to MacOS and that stopped the build from falling. I don't know the reason why it was failing with Ubuntu.

Gitlab CI failure with JHipster

I can build my JHipster gateway with gradle from the development machine, but when I give it to the Gitlab CI I get this error at the 'gradle-package' step:
92 $ ./gradlew bootJar -Pprod -x check --no-daemon
93 To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/6.4.1/userguide/gradle_daemon.html.
94 Daemon will be stopped at the end of the build stopping after processing
95 > Task :bootBuildInfo
96 > Task :nodeSetup SKIPPED
97 > Task :npmSetup SKIPPED
98 > Task :npmInstall UP-TO-DATE
99 > Task :webpack FAILED
100 FAILURE: Build failed with an exception.
101 * What went wrong:
102 Execution failed for task ':webpack'.
103 > A problem occurred starting process 'command 'npm''
This is the .gitlab-ci.yml
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .gradle/
stages:
- check
- build
- test
- analyze
- package
- release
- deploy
before_script:
- export NG_CLI_ANALYTICS="false"
- export GRADLE_USER_HOME=`pwd`/.gradle
- ./gradlew npm_install -PnodeInstall --no-daemon
nohttp:
stage: check
script:
- ./gradlew checkstyleNohttp --no-daemon
gradle-compile:
stage: build
script:
- ./gradlew compileJava -x check -PnodeInstall --no-daemon
artifacts:
paths:
- build/classes/
- build/generated/
expire_in: 1 day
gradle-test:
stage: test
script:
- ./gradlew test -PnodeInstall --no-daemon
artifacts:
reports:
junit: build/test-results/test/TEST-*.xml
paths:
- build/test-results/
- build/jacoco/
expire_in: 1 day
gradle-integration-test:
stage: test
script:
- ./gradlew integrationTest -PnodeInstall --no-daemon
artifacts:
reports:
junit: build/test-results/integrationTest/TEST-*.xml
paths:
- build/test-results/
- build/jacoco/
expire_in: 1 day
frontend-test:
stage: test
script:
- ./gradlew npm_run_test -PnodeInstall --no-daemon
artifacts:
reports:
junit: build/test-results/TESTS-results-jest.xml
paths:
- build/test-results/
- build/jacoco/
expire_in: 1 day
gradle-package:
stage: package
script:
- ./gradlew bootJar -Pprod -x check --no-daemon
artifacts:
paths:
- build/libs/*.jar
- build/classes
expire_in: 1 day
# Uncomment the following line to use gitlabs container registry. You need to adapt the REGISTRY_URL in case you are not using gitlab.com
docker-push:
stage: release
variables:
REGISTRY_URL: 10.1.10.58
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
dependencies:
- gradle-package
script:
- ./gradlew jib -Pprod -Djib.allowInsecureRegistries=true -Djib.to.image=$IMAGE_TAG -Djib.to.auth.username="gitlab-ci-token" -Djib.to.auth.password=$CI_BUILD_TOKEN
build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "https://repo.spring.io/plugins-release" }
}
dependencies {
//jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}
plugins {
id "java"
id "maven-publish"
id "idea"
id "jacoco"
id "org.springframework.boot"
id "com.google.cloud.tools.jib"
id "com.gorylenko.gradle-git-properties"
id "com.github.node-gradle.node"
id "net.ltgt.apt-eclipse"
id "net.ltgt.apt-idea"
id "net.ltgt.apt"
id "org.liquibase.gradle"
id "org.sonarqube"
id "io.spring.nohttp"
//jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}
group = "com.rps.png"
version = "0.0.1-SNAPSHOT"
description = ""
sourceCompatibility=1.8
targetCompatibility=1.8
assert System.properties["java.specification.version"] == "1.8" || "11" || "12" || "13" || "14"
apply from: "gradle/docker.gradle"
apply from: "gradle/sonar.gradle"
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here
if (project.hasProperty("prod") || project.hasProperty("gae")) {
apply from: "gradle/profile_prod.gradle"
} else {
apply from: "gradle/profile_dev.gradle"
}
if (project.hasProperty("war")) {
apply from: "gradle/war.gradle"
}
if (project.hasProperty("gae")) {
apply plugin: 'maven'
apply plugin: 'org.springframework.boot.experimental.thin-launcher'
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom "io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}"
}
}
appengineStage.dependsOn thinResolve
}
if (project.hasProperty("zipkin")) {
apply from: "gradle/zipkin.gradle"
}
idea {
module {
excludeDirs += files("node_modules")
}
}
eclipse {
sourceSets {
main {
java {
srcDirs += ["build/generated/sources/annotationProcessor/java/main"]
}
}
}
}
defaultTasks "bootRun"
springBoot {
mainClassName = "com.rps.png.GatewayuApp"
}
test {
useJUnitPlatform()
exclude "**/*IT*", "**/*IntTest*"
testLogging {
events 'FAILED', 'SKIPPED'
}
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task integrationTest(type: Test) {
useJUnitPlatform()
description = "Execute integration tests."
group = "verification"
include "**/*IT*", "**/*IntTest*"
testLogging {
events 'FAILED', 'SKIPPED'
}
if (project.hasProperty('testcontainers')) {
environment 'spring.profiles.active', 'testcontainers'
}
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
check.dependsOn integrationTest
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn test
}
task integrationTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn integrationTest
}
if (!project.hasProperty("runList")) {
project.ext.runList = "main"
}
project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"
liquibase {
activities {
main {
driver "org.h2.Driver"
url "jdbc:h2:file:./build/h2db/db/gatewayu"
username "gatewayu"
password ""
changeLogFile "src/main/resources/config/liquibase/master.xml"
defaultSchemaName ""
logLevel "debug"
classpath "src/main/resources/"
}
diffLog {
driver "org.h2.Driver"
url "jdbc:h2:file:./build/h2db/db/gatewayu"
username "gatewayu"
password ""
changeLogFile project.ext.diffChangelogFile
referenceUrl "hibernate:spring:com.rps.png.domain?dialect=org.hibernate.dialect.H2Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
defaultSchemaName ""
logLevel "debug"
classpath "$buildDir/classes/java/main"
}
}
runList = project.ext.runList
}
gitProperties {
failOnNoGitDirectory = false
keys = ["git.branch", "git.commit.id.abbrev", "git.commit.id.describe"]
}
checkstyle {
toolVersion '${checkstyle_version}'
configFile file("checkstyle.xml")
checkstyleTest.enabled = false
}
nohttp {
source.include "build.gradle", "README.md"
}
configurations {
providedRuntime
implementation.exclude module: "spring-boot-starter-tomcat"
all {
resolutionStrategy {
// Inherited version from Spring Boot can't be used because of regressions:
// To be removed as soon as spring-boot use the same version
force 'org.liquibase:liquibase-core:3.9.0'
}
}
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
//jhipster-needle-gradle-repositories - JHipster will add additional repositories
}
dependencies {
// import JHipster dependencies BOM
if (!project.hasProperty("gae")) {
implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}")
}
// Use ", version: jhipster_dependencies_version, changing: true" if you want
// to use a SNAPSHOT release instead of a stable release
implementation group: "io.github.jhipster", name: "jhipster-framework"
implementation "javax.annotation:javax.annotation-api"
implementation "org.springframework.boot:spring-boot-starter-cache"
implementation "io.dropwizard.metrics:metrics-core"
implementation "io.micrometer:micrometer-registry-prometheus"
implementation "net.logstash.logback:logstash-logback-encoder"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
implementation "com.fasterxml.jackson.module:jackson-module-jaxb-annotations"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
implementation "com.fasterxml.jackson.core:jackson-annotations"
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.module:jackson-module-afterburner"
implementation "org.apache.httpcomponents:httpclient"
implementation "javax.cache:cache-api"
implementation "org.hibernate:hibernate-core"
implementation "com.zaxxer:HikariCP"
implementation "commons-codec:commons-codec"
implementation "org.apache.commons:commons-lang3"
implementation "commons-io:commons-io"
implementation "javax.transaction:javax.transaction-api"
implementation "org.ehcache:ehcache"
implementation "org.hibernate:hibernate-jcache"
implementation "org.hibernate:hibernate-entitymanager"
implementation "org.hibernate.validator:hibernate-validator"
implementation "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase.ext:liquibase-hibernate5:${liquibase_hibernate5_version}"
liquibaseRuntime sourceSets.main.compileClasspath
implementation "org.springframework.boot:spring-boot-loader-tools"
implementation "org.springframework.boot:spring-boot-starter-mail"
implementation "org.springframework.boot:spring-boot-starter-logging"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-aop"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
testImplementation "org.testcontainers:mysql"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation ("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
implementation "org.springframework.boot:spring-boot-starter-undertow"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.zalando:problem-spring-web"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-zuul"
implementation "com.github.vladimir-bukhtoyarov:bucket4j-core"
implementation "com.github.vladimir-bukhtoyarov:bucket4j-jcache"
implementation "org.springframework.cloud:spring-cloud-starter"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-ribbon"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-hystrix"
implementation "org.springframework.retry:spring-retry"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
implementation "org.springframework.cloud:spring-cloud-starter-config"
implementation "org.springframework.cloud:spring-cloud-starter-security"
implementation "org.springframework.cloud:spring-cloud-starter-openfeign"
implementation "org.springframework.boot:spring-boot-starter-cloud-connectors"
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.security:spring-security-data"
implementation "org.springframework.security:spring-security-web"
implementation "org.springframework.security.oauth:spring-security-oauth2"
implementation "org.springframework.security:spring-security-jwt"
implementation "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
implementation ("io.springfox:springfox-swagger2") {
exclude module: "mapstruct"
}
implementation "io.springfox:springfox-bean-validators"
implementation "mysql:mysql-connector-java"
liquibaseRuntime "mysql:mysql-connector-java"
implementation "org.mapstruct:mapstruct:${mapstruct_version}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct_version}"
annotationProcessor "org.hibernate:hibernate-jpamodelgen:${hibernate_version}"
annotationProcessor "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}"
testImplementation ("org.springframework.boot:spring-boot-starter-test") {
exclude group: "org.junit.vintage", module: "junit-vintage-engine"
}
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "com.tngtech.archunit:archunit-junit5-api:${archunit_junit5_version}"
testRuntimeOnly "com.tngtech.archunit:archunit-junit5-engine:${archunit_junit5_version}"
testImplementation "com.h2database:h2"
liquibaseRuntime "com.h2database:h2"
//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}
if (project.hasProperty("gae")) {
task createPom {
def basePath = 'build/resources/main/META-INF/maven'
doLast {
pom {
withXml(dependencyManagement.pomConfigurer)
}.writeTo("${basePath}/${project.group}/${project.name}/pom.xml")
}
}
bootJar.dependsOn = [createPom]
}
task cleanResources(type: Delete) {
delete "build/resources"
}
wrapper {
gradleVersion = "6.4.1"
}
if (project.hasProperty("nodeInstall")) {
node {
version = "${node_version}"
npmVersion = "${npm_version}"
yarnVersion = "${yarn_version}"
download = true
}
}
compileJava.dependsOn processResources
processResources.dependsOn bootBuildInfo
This is a JHipster gateway 6.9 with only minor changes from the default. In particular, I didnt' touch the 'gradle-package' which is failing on the Gitlab Runner.
What's the [Docker] image you run your job on? I don't see any image: specifications in your .gitlab-ci.yml. Make sure it has npm installed or make sure that your Gradle scripts contains instructions or tasks for installing it. You should probably set nodeInstall property before running the build:
if (project.hasProperty("nodeInstall")) {
node {
version = "${node_version}"
npmVersion = "${npm_version}"
yarnVersion = "${yarn_version}"
download = true
}
}

How to enable Allure history using Gradle and Junit5?

I know I could copy the history directory from allure-reports to a generated allure-results, and then do allure generate to get the history to show up, but I am looking for a way to achieve this with the built-in functionality in allure-gradle.
Currently, I run ./gradlew clean test, then ./gradlew allureReport, and this gives me a fresh html report with no history or reruns. I have noticed that the test task deletes the entire allure-reports directory and then re-makes and re-populates it.
Here is my build.gradle:
buildscript {
repositories {
mavenLocal()
jcenter()
}
}
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'java'
id 'eclipse'
// Allure reporter
id 'io.qameta.allure' version '2.8.1'
}
repositories {
mavenCentral()
jcenter()
}
def allureVersion = "2.13.1"
allure {
autoconfigure = true
version = allureVersion
useJUnit5 {
version = '2.0-BETA10'
}
downloadLink = "https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.13.1/allure-commandline-2.13.1.zip"
}
test {
useJUnitPlatform() {
includeEngines 'junit-jupiter'
}
ignoreFailures = true
}
dependencies {
compile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.0'
compile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.6.0'
compile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.6.0'
// Needed as a workaround for JUnit 5 not failing tests that stopped due to an error message. The fix is in eclipse 4.10
compile group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.6.0'
compile group: 'io.qameta.allure', name: 'allure-junit5', version: '2.13.1'
compile group: 'io.qameta.allure', name: 'allure-java-commons', version: '2.13.1'
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
}
I have also tried specifying the results and reports directories to be outside of the build directory, like this:
allure {
autoconfigure = true
version = allureVersion
resultsDir = file('../../allure-results')
reportDir = file('../../allure-report')
...
}
This allows the allure-results folder to keep the previous report, which show up as retries (not quite right), but history still doesn't work.
I have solved this problem by adding at the running test script these lines( I have some tests scuites)
call gradlew test -PsuiteFile=YOUR_TEST_SUITE.xml
mkdir allure-results\history
xcopy build\allure-results\* allure-results\history
allure serve allure-results\history
So I have added folder allure-results\history to keep all results

Spring boot gradle build and push docker image

I trying to build and push the docker image to my docker hub.After building 90% I am getting error
D:\demo>gradlew jib
> Task :jib
Containerizing application to nithin4325/my-java-image...
Container entrypoint set to [java, -cp, /app/resources:/app/classes:/app/libs/*,
com.example.demo.DemoApplication]
Executing tasks:
[=========================== ] 90.0% complete
> building image to registry
> Task :jib FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':jib'.
> com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: Build
image failed, perhaps you should make sure your credentials for 'nithin4325/my-j
ava-image' are set up correctly.
build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'com.google.cloud.tools.jib' version '1.4.0'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
jib{
to
{
image = 'nithin4325/my-java-image'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.2.2.RELEASE', ext: 'pom'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
I am using windows 7 professional having docker toolbox.I already logged in to dockerhub through command prompt using docker login.

Resources