Jenkins pipeline to verify multpile file existence in when condition - jenkins-pipeline

I need to verify multiple file existence in single when condition using && operation.
check for any file that ends with .doc along with final.txt and proceed further.
Second fileexistence(final.txt) seems to be working fine seperately. Please suggest on this
when {
expression
{
return (fileExists("""ls ${Path}/${version}/test/*.doc""")) && !(fileExists("""${Path}/${Version}/test2/final.txt"""))
}
}

You could use allOf and not
when {
allOf {
expression {
return fileExists("ls ${Path}/${version}/test/*.doc")
}
not {
expression {
return fileExists("${Path}/${Version}/test2/final.txt")
}
}
}
}

Related

Laravel Pint json config not wokring

I've been playing around with Laravel Pint and I can't seem to make it work the way I want.
My goal is to have the curly brackets inline with class or function
so instead
function test()
{
}
I want to have a format like this
function test() {
}
I have this on pint.json but doesn't change anything.
{
"preset": "laravel",
"braces": {
"position_after_functions_and_oop_constructs": "same",
"position_after_anonymous_constructs": "same"
}
}
I event tried using psr12 preset and still does not change anything
{
"preset": "psr12"
}
Additionally, I'd like to know how I can allow this format
if ( !$num )
return;
it changes to this after running pint, (it removes the space between if condition and added a space after ! and wrap the state with brackets)
if (! $num) {
return;
}
The rule in a pint.json will be
{
"preset": "laravel",
"rules": {
"not_operator_with_successor_space": false,
"curly_braces_position": {
"functions_opening_brace": "same_line",
"classes_opening_brace": "same_line"
}
}
}
As per PHP-CS-Fixer Rule, use curly_braces_position
Ref: How with pint can I remove space after negative “!” symbol?

get rawTextBlob from all repository files matching path glob pattern

GraphQL beginner here. I am looking out for something like a SQL join so that I may feed the list of repository files from one query as criteria for another query.
I can get a nice result if I know the file path from each project like this:
{
group(fullPath: "group/path") {
projects {
nodes {
name
repository {
blobs(paths: ["global.tfvars"]) {
nodes {
rawTextBlob
}
}
}
}
}
}
}
But what if I don't know the exact file paths up front, e.g I need all the files matching environments/*/local.tfvars
If specifying a glob pattern is not an option, then I would think that need some kind of join with something like this:
{
group(fullPath: "group/path") {
id
name
projects {
nodes {
name
repository {
paginatedTree(path: "environments", recursive: true) {
nodes {
blobs {
nodes {
path
}
}
}
}
}
}
}
}
}

GraphQL using a field as argument in the same query

I have constructed the following query in Gitlab's GraphQL Explorer to show my question:
https://gitlab.com/-/graphql-explorer
{
project(fullPath: "gitlab-org/gitlab") {
name
repository {
rootRef
}
mergeRequests(state: merged, targetBranches: "master") {
nodes {
sourceBranch
targetBranch
}
}
}
}
What I would like to achieve is using the value of repository { rootRef } as the argument for targetBranches.
Something like this:
mergeRequests(state: merged, targetBranches: repository { rootRef }) {
Can it be done?
Thank you!

Conditional input step in declarative pipeline

using Jenkins v2.138.2 and workflow-aggregator v2.6, I'm trying to define a conditional input step that depends on the value of a job parameter as follows:
stage('apply') {
when { expression { params.apply_plan != 'no' } }
if (params.apply_plan != 'yes') {
input {
message 'Apply this plan?'
}
}
steps {
withAWS(region: 'us-east-1', role: assume_role) {
dir(path: tf_dir) {
sh "make apply"
}
}
}
}
However this if { ( ... ) input { ...} } syntax gives me a run-time error:
java.lang.ClassCastException: org.jenkinsci.plugins.workflow.support.steps.input.InputStep.message expects class java.lang.String but received class org.jenkinsci.plugins.workflow.cps.CpsClosure2
Any idea how to do this?
Thanks,
Chris
I think you are using the wrong syntax here. The input { … } is only valid as a directive (outside of the steps directly below stage). What you want to use is the input step which is described here. Basically you just need to remove the curly braces and put it into a script within steps:
stage("stage") {
steps {
script {
if (params.apply_plan != 'yes') {
input message: 'Apply this plan?'
}
}
withAWS(region: 'us-east-1', role: assume_role) {
dir(path: tf_dir) {
sh "make apply"
}
}
}
}

Does the completions file "contents" have to be 1 line (no newline)?

New to sublime text and trying to setup some completions as I have a bunch of snippets and I'd rather just use 1 file, instead of separate files for each snippet.
When I save the below code, I get the error that it can't parse the file, unexpected newline. I'd assume it's because I'm using linebreaks. Are completions only for short 1 line code? Is there anything that can be done so I don't have to use individual files for snippets when I have longer code like below?
{
"completions":
[
{ "trigger": "clearforms", "contents":
"//clear form fields
\$(function() {
\$.fn.clearInput = function() {
return this.focus(function() {
if( this.value == this.defaultValue ) {
this.value = "";
}
}).blur(function() {
if( !this.value.length ) {
this.value = this.defaultValue;
}
});
};
\$('#subscribe').clearInput();
\$('#search').clearInput();
});"
}
]
}
JSON does not allow multi-line strings - the line breaks need to be encoded as \n. The $ symbol needs to be double-escaped like so \\$, and your comment forward slashes single-escaped like so - \/\/. So, your completions file needs to look like this:
{
"completions":
[
{ "trigger": "clearforms", "contents": "\/\/ clear forms \n\\$(function() { \n\\$.fn.clearInput = function() { \nreturn this.focus(function() { \nif( this.value == this.defaultValue ) { \nthis.value = \"\"; \n} \n}).blur(function() { \nif( !this.value.length ) { \nthis.value = this.defaultValue; \n} \n}); \n}; \n\n\\$('#subscribe').clearInput(); \n\\$('#search').clearInput(); \n});" }
]
}
I'll leave it up to you to put in the appropriate whitespace after each line break. I should note that while it may be slightly more "clutter-y" to have individual snippet files, they do allow multi-line entries with no newline escaping needed, allowing you to format your output more easily. However, the $ and possibly the JS comments might need escapes.

Resources