Configure Jenkin's SonarQube section using Job-DSL - groovy

Using Job-DSL we can configure a C# project in Jenkins.
The SonarQube tasks is giving us a hard time.
StepContext.metaClass.sonar = {
-> NodeBuilder nodeBuilder = new NodeBuilder()
stepNodes << nodeBuilder.'hudson.plugins.sonar.SonarRunnerBuilder' {
jdk('(Inherit From Job)')
usePrivateRepository(false)
}
}
How to set the path to the sonar-project.properties config file, using the Job-DSL script?
Final script
Thanks to #Bruno César, I added pathToSonarProjectProperties as parameter.
StepContext.metaClass.sonar = { String pathToSonarProjectProperties
-> NodeBuilder nodeBuilder = new NodeBuilder()
stepNodes << nodeBuilder.'hudson.plugins.sonar.SonarRunnerBuilder' {
jdk('(Inherit From Job)')
usePrivateRepository(false)
project(pathToSonarProjectProperties)
}
}
The sonar function is called with the relative-to-project-root path of sonar-project.properties:
sonar("Framework\\xxx\\xxx\\sonar-project.properties")

In SonarRunnerBuilder class there is a project attribute that represents the path to a file with properties for the project.
In the same way in which you set the JDK (jdk('(Inherit From Job)')) you can set the path property. In your example, try like this:
StepContext.metaClass.sonar = {
-> NodeBuilder nodeBuilder = new NodeBuilder()
stepNodes << nodeBuilder.'hudson.plugins.sonar.SonarRunnerBuilder' {
jdk('(Inherit From Job)')
usePrivateRepository(false)
project('${your.path.here}')
}
}

Related

Accessing a complex key in a config file

I'm trying to access a variable in a nextflow.config file during the execution of a pipeline. I want to supply image_standard as a string in run.nf and I want to receive eu.gcr.io/proj_name/image1:latest as an output. I figured out a way to obtain the content of the .config file within the nextflow script, but I don't know how to access this specific property.
This is my nextflow.config file:
process {
withLabel: image_standard {
container = "eu.gcr.io/proj_name/image1:latest"
}
withLabel: image_deluxe {
container = "eu.gcr.io/proj_name/image2:latest"
}
}
the run.nf
x = workflow.configFiles[0]
Properties properties = new Properties()
File propertiesFile = new File("${x}")
propertiesFile.withInputStream {
properties.load(it)
}
log.info "${properties.process}"
Which just prints the line:
{
You could try instead slurping the config file and selecting the process you want using the ProcessConfig class and the applyConfigSelector() method:
import nextflow.config.ConfigParser
import nextflow.script.ProcessConfig
def config_file = file("${baseDir}/nextflow.config")
def config = new ConfigParser().setIgnoreIncludes(true).parse(config_file.text)
def process = new ProcessConfig([:])
process.applyConfigSelector(config.process, 'withLabel:', 'image_standard')
println(process.container)

How to perform a Jooq code re-generation?

I'm using Jooq and gradle-jooq-plugin for code generation. It works fine, but I'm having a problem getting the generated code to update when a table is added or a column is dropped. I was able to force an update by changing the "packageName" config parameter and build a new package. And by going back to the original name the code was updated as expected.
What would be the correct way to re-generate code after schema change with my setup?
jooq {
version = '3.13.1'
edition = 'OSS'
generateSchemaSourceOnCompilation = true
sample(sourceSets.main) {
jdbc {
driver = 'org.postgresql.Driver'
url = 'jdbc:postgresql://0.0.0.0:5432/victor'
user = 'postgres'
password = 'docker'
properties {
property {
key = 'ssl'
value = 'false'
}
}
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
strategy {
name = 'org.jooq.codegen.DefaultGeneratorStrategy'
}
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = 'public'
forcedTypes {
forcedType {
name = 'varchar'
expression = '.*'
types = 'INET'
}
}
}
generate {
relations = true
deprecated = false
records = true
immutablePojos = true
fluentSetters = true
}
target {
packageName = 'net.bravo.victor.model'
directory = 'src/'
}
}
}
I'm using https://github.com/etiennestuder/gradle-jooq-plugin
plugins {
id 'nu.studer.jooq' version '4.1'
}
I am not sure whether it is correct way but for me works this:
generateNavigoJooqSchemaSource {
dependsOn cleanGenerateNavigoJooqSchemaSource
}
task buildJooq(dependsOn: generateNavigoJooqSchemaSource)
So I have created task name (buildJooq) I can remember that depends on generate task (generateNavigoJooqSchemaSource) and that depends on clean (cleanGenerateNavigoJooqSchemaSource) task.
Previously I have used this code which works too:
tasks.named("generateNavigoJooqSchemaSource").configure {
outputs.upToDateWhen { false }
}
It also forces run every time.

puppet defined types and variables

I am new to puppet and I am trying to write a module to manage .bashrc file of 10 users. The following code is ok to manage the file of 1 user. However, I am unable to change the code to manage files for 10 users. I tried using defined types and variable with no luck. Can sombody please suggest me the right way to do this.
init.pp:
class profile (
$bashrc = $profile::params::bashrc,
$bashrc_host = $profile::params::bashrc_host,
) inherits profile::params {
anchor { 'profile::begin': } ->
class { '::profile::config': } ->
anchor { 'profile::end': }
}
config.pp:
class profile::config inherits profile {
file { $bashrc:
ensure => file,
source => "puppet:///$bashrc_host",
}
params.pp:
class profile::params {
$bashrc_host = "modules/profile/$fqdn_user1_bashrc"
}
case $::osfamily {
'RedHat': {
$bashrc = '/home/user1/.bashrc'
}
}
This is not at all a job for a class. As you noted yourself in your most recent comment, this calls for a define actually.
Please don't use verbs in the names of your defines. Instead of defineuser, just do
define profile::user($host_name) {
}
Off the top of my hat, I'm not aware of a good pattern to use module parameters in your defines. You can however use the following pattern:
class profile(
$default_shell = $profile::params::default_shell,
$default_prompt = $profile::params::default_prompt,
$users = {}
) inherits profile::params {
$defaults = { shell => $default_shell, prompt => $default_prompt }
create_resources('profile::user', $users, $defaults)
}
What happens is
values are taken from params, or hiera, or the invoking manifest
these values are gathered in the $defaults array
for any resource in the $users hash that has no shell or prompt, this default is used
If your aim of this module is to learn puppet then:
Add a param user to your class profile::params
class profile::params {
$bashrc_host = "modules/profile/$fqdn_user1_bashrc"
$user = 'user1',
}
case $::osfamily {
'RedHat': {
$bashrc = "/home/$user/.bashrc"
}
}
After this, you can use a combination of array or hiera and ensure_resource This still is not the most elegant solution, but baby steps.
If your intend is to actually manage the bashrc for various users, I would recommend using a pre existing module such as account

Gradle passing arguments to a plugin task

I have this tasks from gradle-js-plugin:
combineJs {
source = sourceJs
dest = file(destDirJs + "/all.js")
}
minifyJs {
source = combineJs
dest = file( destDirJs + "/all-min.js")
closure {
warningLevel = 'QUIET'
}
}
gzipJs {
source = minifyJs
dest = file(destDirJs + "/all-gzip-min.js")
}
My problem is because I´ll have to change the values of sourceJs, and destDirJs multiple times. So I dont want to have alot of duplicated code.
So I´m trying something like this:
task gzipAll {
sourceJs = ["WebContent/plugin/bootstrap-modal/js/bootstrap-modalmanager.js", "WebContent/plugin/bootstrap-modal/js/bootstrap-modal.js", "WebContent/js/bootstrap-dropdown.js", "WebContent/js/mandatory/bootstrap-analytics-setup.js"]
destDirJs = "WebContent/js/mandatory"
tasks.combineJs().execute;
tasks.minifyJs().execute;
tasks.gzipJs().execute;
//Here I need to change sourceJs and destDir and call all the task again.
}
Actually I was tring a long shot in the dark, and I got the exception:
Caused by: groovy.lang.MissingPropertyException: Could not find property 'sourceJs' on task ':combineJs'.
I also tried something like this, but didnt work. Got some exceptions:
combineJs(sourceJs, destDirJs) {
source = $sourceJs
dest = file($destDirJs + "/all.js")
}
Can anyone with more experience help me solve this ? It´s kinda simple right?
Thanks.
I've not tested it but since gradle scripts are groovy scripts you should be able to do something like this.
['dir1', 'dir2'].eachWithIndex { dir, index ->
task "combineJs_$index"(type: combineJs) {
source = dir
dest = file(destDirJs + "/$index.js")
}
task "minifyJs_$index" (type: minifyJs) {
source = "combineJs_$index"
dest = file( destDirJs + "/$index-min.js")
closure {
warningLevel = 'QUIET'
}
}
task "gzipJs_$index" (type: gzipJs) {
source = "minifyJs_$index"
dest = file(destDirJs + "/$index-gzip-min.js")
}
}
Of course you need the correct TaskTypes and you'll probably need the change the input, but this should get you going.

Puppet - setting variables

I have this in my puppet fle for solr:
define solr::core(
$solr_home = "/opt/solr",
$schema_xml = "searchapi_schema.xml",
$solrconfig_xml = "searchapi_solrconfig.xml",
$user = 'jetty'
) { ..
I would like to in my node override the variables for $schema_xml and $solrconfig_xml, how do I do that in a nice way?
I tried this:
node web02 inherits webbasenode {
$schema_xml = "apachesolr_schema.xml"
$solrconfig_xml = "apachesolr_solrconfig.xml"
...
But that did not work out.
It looks like, you need your definition to accept parameters. For example
define solr::core ($schema_xml = "searchapi_schema.xml",
$solrconfig_xml = "searchapi_solrconfig.xml"){ .... }
In your node, call the definition with the updated parameters. For example
node web02 inherits webbasenode {
solr::core {
schema_xml => "apachesolr_schema.xml",
solrconfig_xml => "apachesolr_solrconfig.xml"
}
}

Resources