I am trying to update a project from gradle 6.9 to 7.6 version. Mainly I did some changes in the build.gradle file, such as:
In the plugins section I did:
from:
plugins {
id 'org.jetbrains.intellij' version '1.5.2'
id 'jacoco'
id 'groovy'
id 'signing'
id 'maven'
id 'maven'
}
to:
plugins {
id 'org.jetbrains.intellij' version '1.5.2'
id 'jacoco'
id 'groovy'
id 'signing'
id 'maven'
id 'maven-publish'
}
Basically I changed the maven plugin to maven-publish and I had to change the uploadArchives method to publishing such as:
from:
if (project.hasProperty('deployment')) {
uploadArchives {
repositories {
mavenDeployer {
pom.artifactId = 'my-plugin'
pom.project {
licenses {
license {
name = 'company Proprietary'
url = 'http://links.company.com/license/lisce'
}
}
}
repository(url: repo.url) {
authentication(userName: deployment.release.username, password: deployment.release.password)
}
snapshotRepository(url: deployment.snapshot.url) {
authentication(userName: deployment.snapshot.username, password: deployment.snapshot.password)
}
}
}
}
}
to:
if (project.hasProperty('deployment')) {
uploadArchives {
repositories {
mavenDeployer {
pom.artifactId = 'my-plugin'
pom.project {
licenses {
license {
name = 'company Proprietary'
url = 'http://links.company.com/license/lisce'
}
}
}
repository(url: repo.url) {
authentication(userName: deployment.release.username, password: deployment.release.password)
}
snapshotRepository(url: deployment.snapshot.url) {
authentication(userName: deployment.snapshot.username, password: deployment.snapshot.password)
}
}
}
}
}
In my local environment, when I build the project with build.gradle with the 7.6 version it worked, but in Jenkins I got the next error:
Caused by: groovy.lang.MissingMethodException: No signature of method: build_dxy89r3f9eem3p61x49m9xluc.publishing() is applicable for argument types: (build_dxy89r3f9eem3p61x49m9xluc$_run_closure8) values: [build_dxy89r3f9eem3p61x49m9xluc$_run_closure8#4045ba37]
Not sure why is happening just on Jenkins and there are not enough info for me to figure out how can I solve it.
Any ideas?
Thanks!
Related
how to i set discard old build in this script code in jenkins pipelinejob?
i am using this config in jenkins helm value on kubernetes
- script: >
pipelineJob('my-job') {
properties {
disableConcurrentBuilds()
pipelineTriggers {
triggers {
gitlab {
triggerOnPush(true)
branchFilterType('NameBasedFilter')
includeBranchesSpec('staging')
secretToken('123456')
cancelPendingBuildsOnUpdate(true)
}
}
}
}
definition {
cpsScm {
scriptPath 'jenkinsfile'
scm {
git {
remote {
credentials 'user'
url 'git-repo'
}
branch 'staging'
extensions {}
}
}
}
}
}
I find it.
- script: >
pipelineJob('my-job') {
logRotator {
numToKeep(10)
artifactNumToKeep(10)
}
properties {
disableConcurrentBuilds()
pipelineTriggers {
triggers {
gitlab {
triggerOnPush(true)
branchFilterType('NameBasedFilter')
includeBranchesSpec('staging')
secretToken('123456')
cancelPendingBuildsOnUpdate(true)
}
}
}
}
definition {
cpsScm {
scriptPath 'jenkinsfile'
scm {
git {
remote {
credentials 'user'
url 'git-repo'
}
branch 'staging'
extensions {}
}
}
}
}
}
I've a pipeline where multiple stages run in parallel but if any of the stages fails, I want to get its name to show failed stage. With following code, even if it fails in first stage ie Checking Redmine access, it always show last stage as failed i.e. Checking Reviewers list. This is because it runs in parallel and latest assigned value is picked up.
pipeline {
agent {
label {
label "<machine-ip>"
customWorkspace "workspace/RedmineAndReviewboardProject/SVNCheckoutTest"
}
}
stages {
stage('Verify inputs') {
parallel {
stage('Checking Redmine access') {
steps {
script {
FAILED_STAGE = env.STAGE_NAME
echo "Redmine"
sh'''hello'''
}
}
}
stage('Checking SVN access') {
steps {
script {
FAILED_STAGE = env.STAGE_NAME
echo "SVN"
}
}
}
stage('Checking Reviewers list') {
steps {
script {
FAILED_STAGE = env.STAGE_NAME
echo "Reviewer"
}
}
}
}
}
}
post {
failure {
script {
echo "Failed stage is " + FAILED_STAGE
}
}
}
}
Is there any way I can get exactly failed stage of parallel running stages? or it will be also ok with me if parent stage name is returned as failed stage.
I believe you can use a post { failure { block for each stage : see https://www.jenkins.io/doc/book/pipeline/syntax/#post
pipeline {
agent {
label {
label "<machine-ip>"
customWorkspace "workspace/RedmineAndReviewboardProject/SVNCheckoutTest"
}
}
stages {
stage('Verify inputs') {
parallel {
stage('Checking Redmine access') {
steps {
script {
echo "Redmine"
sh'''hello'''
}
}
post {
failure {
script {
echo "Failed stage is ${STAGE_NAME}"
}
}
}
}
stage('Checking SVN access') {
steps {
script {
FAILED_STAGE = env.STAGE_NAME
echo "SVN"
}
}
post {
failure {
script {
echo "Failed stage is ${STAGE_NAME}"
}
}
}
}
stage('Checking Reviewers list') {
steps {
script {
FAILED_STAGE = env.STAGE_NAME
echo "Reviewer"
}
}
post {
failure {
script {
echo "Failed stage is ${STAGE_NAME}"
}
}
}
}
}
}
}
}
We use Jenkins 2.176 to manage our CI. In our Jenkinsfile, we've defined a trigger to start the pipeline M-F at 4:30AM, and we want it to skip testing in an ephemeral environment and deploying.
pipeline {
triggers { cron('30 4 * * 1-5') }
stages {
stage('Build') {
...
}
stage('Tests') {
...
}
stage('Test in ephemeral environment') {
when { triggeredBy 'SCMTrigger' }
steps {
...
}
}
stage('Deploy') {
when { allOf { branch 'master'; triggeredBy 'SCMTrigger' } }
steps {
...
}
}
}
}
The problem is: the "Test in ephemeral environment" does not trigger when the branch is pushed via a git hook. The "Build" and "Tests" stages execute, but not the "Test in ephemeral environment". Once merged to master, I suspect I'll have a similar problem with the "Deploy" step but haven't made it that far.
What am I missing to make this work? It seems so straightforward 🤔
My solution was to simply exclude TimerTrigger explicitly from steps I didn't want to execute. From my example, I did this:
pipeline {
triggers { cron('30 4 * * 1-5') }
stages {
stage('Build') {
...
}
stage('Tests') {
...
}
stage('Test in ephemeral environment') {
when { not { triggeredBy 'TimerTrigger' } }
steps {
...
}
}
stage('Deploy') {
when { allOf { branch 'master'; not { triggeredBy 'TimerTrigger' } } }
steps {
...
}
}
}
}
In a declarative Jenkinsfile how can you determine if a job exists?
I want to conditionally run a stage if another job exists, like so:
pipeline {
agent { label 'mylabel' }
// Run the the stages:
stages {
stage('Pre-Build') {
steps {
timestamps { ansiColor('xterm') { sh 'build/jenkins_prebuild.sh' } }
}
}
stage('Pre-Build') {
steps {
timestamps { ansiColor('xterm') { sh 'build/jenkins_build.sh' } }
}
}
stage('Trigger Remote If Exists'){
when { JOB_EXISTS }
steps {
timestamps {
ansiColor('xterm') {
sh 'build/pre-trigger.sh'
build job: "../myjob/foo", wait: false, parameters: [booleanParam(name: 'FOO', value: true)]
}
}
}
}
}
}
Basically, what should I do for JOB_EXISTS?
if (jenkins.model.Jenkins.instance.getItem("YOUR_JOB_NAME") != null) {
}
You may not be able to use the above snippet in your declarative pipeline. But you should be able to use this in a global shared lib.
UPDATE:
An administrator needs to approve this snippet in "Manage Jenkins -> In-process Script Approval" section.
There is also this option: https://stackoverflow.com/a/52076776/3384609
try {
println("Preparing to build the ${jobName}...")
build job:"${jobName}", propagate:false, wait:false
} catch (hudson.AbortException e) {
println("Not building the job ${jobName} as it doesn't exist")
}```
springSecurityService service in User is always null
I can't seem to reference the package itself in the following manner
import grails.plugin.springsecurity.*;
though spring security login page does appear, and gradle doesn't complain on anything missing.
seems like no DI is taking place.
User
package com.sciencecanvas.mykingdom
class User implements Serializable {
private static final long serialVersionUID = 1
transient springSecurityService
String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
User(String username, String password) {
//this()
this.username = username
this.password = password
}
#Override
int hashCode() {
username?.hashCode() ?: 0
}
#Override
boolean equals(other) {
is(other) || (other instanceof User && other.username == username)
}
#Override
String toString() {
username
}
Set<Role> getAuthorities() {
UserRole.findAllByUser(this)*.role
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
}
static transients = ['springSecurityService']
static constraints = {
username blank: false, unique: true
password blank: false
}
static mapping = {
password column: '`password`'
}
}
my build :
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0'
classpath "org.grails.plugins:hibernate:4.3.10.5"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
id 'com.jfrog.bintray' version '1.2'
}
version "0.1"
group "monopolyserver"
apply plugin: 'maven-publish'
apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: "asset-pipeline"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
//custom plugins
compile 'org.grails.plugins:spring-security-core:3.0.0.M1'
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile 'mysql:mysql-connector-java:5.1.36'
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:scaffolding"
//compile ':spring-security-core:2.0-RC5'
runtime "org.grails.plugins:asset-pipeline"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
// Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0'
console "org.grails:grails-console"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
Service injection in GORM entities is disabled by default since Grails 3.2.8. Because of that, if you want the service springSecurityService to get injected in the previous domain class you would need to turn on autowire.
grails-app/conf/application.yml
grails:
gorm:
# Whether to autowire entities.
# Disabled by default for performance reasons.
autowire: true
It's because you commented out this() in the constructor - that line of code calls the generated default constructor which does DI. This is described in the "what's new" section of the docs. Either delete the constructor and use the traditional map constructor, or restore that line of code.
You can try Holders.applicationContext.getBean('springSecurityService') instead of injecting it.