How to display in a project that is called from another pipeline project in jenkins text in "Edit Build Information" - selenium

Hello: I have a pipeline project at Jenkins called "ProjectLaunch" that launches other projects automatically one day a week. I would like to show in "Edit Build Information" a text that says something like "ProjectCalled full launched", in the project that is called. With the pipeline I have in "ProjectLaunch" I can only get that text in its "Edit Execution Information" but not in the projects called.
My pipeline:
pipeline {
agent any
stages {
stage('Proyect called') {
steps{
build job: 'Proyect called',string(name: "DESCRIPTION", value: "ProjectCalled full launched") ]
}
}
}
}
In the project called in the configuration I have an Execute system Groovy script, it is this:
import hudson.model.*
def build = manager.build
def params = build.action(hudson.model.ParametersAction).getParameters()
def description = "${params.DESCRIPTION}"
echo "Setting build description to: ${description}"
build.createSummary("Build description").appendText(description, "html")
But when I launch it I get this error:
Caught: groovy.lang.MissingPropertyException: No such property: manager for class: hudson1130775177255181016
groovy.lang.MissingPropertyException: No such property: manager for class: hudson1130775177255181016
Any ideas?
Thank you.

As far as I know, you can't set the build description of a downstream job from an upstream Job. Hence in your Downstream Job, you can have some logic to set the description based on the trigger.
pipeline {
agent any
stages {
stage('Hello') {
steps {
script {
echo 'Your second Job'
if(currentBuild.getBuildCauses()[0]._class == "org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamCause") {
echo "This is triggered by upstream Job"
currentBuild.description = "ProjectCalled full launched."
}
}
}
}
}
}

I've done the following because with Groovy I couldn't do it. I installed "Build Name and Description Setter" plugin. In the "ProjectLaunch" pipeline project, the pipeline would be more or less like this:
Pipeline {
agent any
parameters{
string(name: "DESCRIPTION", defaultValue: "ProjectCalled full launched", description: "")
}
stages {
stage('ProjectCalled') {
steps{
build job: 'ProjectCalled', parameters: [string(name: "DESCRIPTION", value: params.DESCRIPTION)]
}
}
}
}
And in the ProjectCalled in settings, add a parameter, I select the plugin option Changes build description, and I write ${DESCRIPTION}.
Changes build description
Ah!, I have also created string parameter named DESCRIPTION and without value.
String parameter

Related

Groovy URL getText() returns a PasswordAuthentication instance

I am trying to download the content of a password-protected Gerrit URL in a Jenkins pipeline Groovy script. HTTPBuilder is not accessible so I am using the URL class with Authenticator:
// To avoid pipline bailing out since data PasswordAuthentication is non-serializable
#NonCPS
def getToString(data) {
data.toString()
}
def fetchCommit(host, project, version) {
withCredentials([usernamePassword(credentialsId: 'my-credentials',
usernameVariable: 'user',
passwordVariable: 'PASSWORD')]) {
proj = java.net.URLEncoder.encode(project, 'UTF-8')
echo "Setting default authentication"
Authenticator.default = {
new PasswordAuthentication(env.user, env.PASSWORD as char[])
} as Authenticator
echo "https://${host}/a/projects/${proj}/commits/${version}"
url = "https://${host}/a/projects/${proj}/commits/${version}".toURL()
result = getToString(url.getText())
echo "${result}"
}
}
The result is a PasswordAuthentication instance, and not the expected data:
[Pipeline] echo
java.net.PasswordAuthentication#3938b0f1
I have been wrestling with this for a while. I have tried different ways to setup the authentication and reading the data, but those mostly end up with an exception. Using eachLine() on the url does not enter the closure at all. The job also exits far to quickly, giving the impression it not even tries to make a connection.
Refs:
https://kousenit.org/2012/06/07/password-authentication-using-groovy/

ECS scheduled task containerOverrides for entryPoint not working

I'm creating a scheduled ECS task in Terraform. When I try to override the container definition for the entryPoint, the resulting task does not use the overridden entryPoint. However, if I try to override the command, it works fine (adds a new command in addition to existing entry point). I cannot find anything in the docs that lead me to believe that there is no support for entryPoint overriding but that may be the case?
Below is the code for the Cloudwatch event target in terraform
resource "aws_cloudwatch_event_target" "ecs_task" {
target_id = "run-${var.task_name}-scheduled"
arn = "${var.cluster_arn}"
rule = "${aws_cloudwatch_event_rule.ecs_task_event_rule.name}"
role_arn = "${aws_iam_role.ecs_event.arn}"
ecs_target = {
launch_type = "${var.launch_type}"
network_configuration = {
subnets = ["${var.subnet_ids}"]
security_groups = ["${var.security_group_ids}"]
}
task_count = 1
task_definition_arn = "${var.task_arn}"
}
input = <<DOC
{
"containerOverrides": [
{
"name": "${var.task_name}",
"entryPoint": ${jsonencode(var.command_overrides)}
}
]
}
DOC
}
This creates a new scheduled task on the AWS console, where the input field is the following:
{
"containerOverrides": [
{
"name": "my-container-name",
"entryPoint": [
"sh",
"/my_script.sh"
]
}
]
}
However tasks launched by this rule do not have the entry point override and use the entrypoint defined in the original task definition.
TLDR: How can I override the entrypoint for a scheduled task?
As of today, only a certain number of fields can be overridden as the scheduled task ultimately uses the run-task API. These fields are the following:
command
environment
taskRoleArn
cpu
memory
memoryReservation
resourceRequirements
Container definitions for other fields are not supported, such as entryPoint, portMappings, and logConfiguration.
The solution is to use command instead of entryPoint in the original task definition, as command can be overridden but entryPoint cannot.

basic puppet construct not working, why?

I have created a puppet construct: the file-scructure can be taken out of the screenshot below.
But when I execute the sites.pp file with the following command...
sudo puppet apply manifests/sites.pp --modulepath=~/puppet/modules/
...I get an errormessage as it is shown in the screenshot below.
manifests/sites.pp:
import 'nodes.pp'
manifests/nodes.pp:
node 'rbalwprinst01' {
include teamviewer
}
modules/teamviewer/manifests/init.pp:
class teamviewer {
file { '/tmp/test':
content => "test",
}
}
What is the cause of this error?
Thanks in advance.
EDIT: The solution to the problem was to remove "sudo", so that the command gets executed by the normal user.

How do you include multiple activities in the Gradle Liquibase plugin's runList field?

I’m using Gradle 2.7 on Mac Yosemite with Java 8. I’m using the Liquibase 1.1.1 plugin and would like to use it to do a couple of activities (build a test database and build my normal database). So I have
liquibase {
activities {
main {
File propsFile = new File("${project.rootDir}/src/main/resources/liquibase.properties")
Properties properties = new Properties()
properties.load(new FileInputStream(propsFile))
changeLogFile 'src/main/resources/db.changelog-master.xml'
url properties['url']
username properties['username']
password properties['password']
}
test {
url 'jdbc:h2:file:target/testdb'
username 'sa'
}
runList = (
"test"
"main"
)
}
}
But I can’t figure out the proper syntax for runList. I get the error when running the above …
* Where:
Build file '/Users/myuser/Dropbox/cb_workspace/cbmyproject/build.gradle' line: 163
* What went wrong:
Could not compile build file '/Users/myuser/Dropbox/cb_workspace/cbmyproject/build.gradle'.
> startup failed:
build file '/Users/myuser/Dropbox/cb_workspace/cbmyproject/build.gradle': 163: expecting ')', found 'main' # line 163, column 2.
"main"
^
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
According to one of there example, the runList must be placed after the activity block:
liquibase {
activities {
main {
File propsFile = new File("${project.rootDir}/src/main/resources/liquibase.properties")
Properties properties = new Properties()
properties.load(new FileInputStream(propsFile))
changeLogFile 'src/main/resources/db.changelog-master.xml'
url properties['url']
username properties['username']
password properties['password']
}
test {
url 'jdbc:h2:file:target/testdb'
username 'sa'
}
}
runList = 'test, main'
}
See the example here.
Hope this helps.

Gradle ternary/elvis operator not setting 'else' value when external property not set

The 'else' value of the elvis/ternary operator in my gradle build file is not setting the property value if I do not run gradle with the "-P" option.
Here's the root project's build.gradle
defaultTasks 'loadConfiguration'
task loadConfiguration << {
def profile = hasProperty('profile') ? profile : 'dev'
ext.profile = profile
def configFile = file('profile.properties')
def config = new ConfigSlurper(profile).parse(configFile.toURL())
ext.config = config
}
configure (subprojects) {
profile = profile //inject property into sub-project
println profile
task buildear << {
ear
}
}
The sub-project 'ear' is in the settings.gradle file.
Below are the results of a build attempt-
With external property set:
$ gradle -Pprofile=wwww
Parallel execution is an incubating feature.
wwww
wwww
wwww
:loadConfiguration
BUILD SUCCESSFUL
Total time: 5.834 secs
With empty external property set:
$ gradle -Pprofile
Parallel execution is an incubating feature.
:loadConfiguration
BUILD SUCCESSFUL
Total time: 5.389 secs
With no external property set:
$ gradle
Parallel execution is an incubating feature.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/robert/codingk/kazi/trunk2/mazama2/build.gradle' line: 13
* What went wrong:
A problem occurred evaluating root project 'mazama2'.
> Could not find property 'profile' on project ':ear'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.104 secs
Line 13 is the line "profile = profile //inject property into sub-project"
I cannot figure out why the 'profile' property is not getting set to 'dev'. A few things I've tried without success:
profile= "${profile}
def profile = project.hasProperty('profile') ? profile : 'dev'
project.ext.profile = profile
some remarks about your initial build script.
In your initial build script you declared a task (loadConfiguration) to set the profile. This logic is executed AFTER the configure block below
is executed. That's one reason why "profile" is always null in the configuration block
The second problem is, that you need to be careful about scoping. In the snippet
ext.profile = profile
you add a dynamic property to the loadConfiguration task, not to the project itself. That's why you can't reference
The profile property if you havn't passed it via commandline.
Maybe instead of doing the configuration loading in a seperate task, do it on the top level of your build:
ext.profile = hasProperty('profile') ? profile : 'dev'
def configFile = file('profile.properties')
def config = new ConfigSlurper(profile).parse(configFile.toURL())
ext.config = config
configure (subprojects) {
profile = profile //inject property into sub-project
println profile
task buildear << {
ear
}
}
Got it working with the following modifications. I may be wrong but I believe it had to do with task ordering; declaring loadConfiguration() as a default task did not cause it to be executed first which is what I needed
def loadConfiguration() {
def profile = hasProperty('profile') ? profile : 'dev'
ext.profile = profile
def configFile = file('profile.properties')
def config = new ConfigSlurper(profile).parse(configFile.toURL())
ext.config = config
}
configure (subprojects) {
loadConfiguration()
profile = profile //inject property into sub-project
println profile
task buildear << {
ear
}
}