How to use generic trigger in jenkins to retrigger a pull request - jenkins

I have a question, how to use generic trigger in jenkis to retrigger a pull request.
if I give "Rebuild" in comment in a pull request, a pipeline should be triggerd.
genericVariables {
genericVariable {
key("action")
value("\$.action")
expressionType("JSONPath") //Optional, defaults to JSONPath
regexpFilter("") //Optional, defaults to empty string
defaultValue("") //Optional, defaults to empty string
}
genericVariable {
key("commit_sha")
value("\$.pull_request.head.sha")
expressionType("JSONPath") //Optional, defaults to JSONPath
regexpFilter("") //Optional, defaults to empty string
defaultValue("\$.pull_request.head.sha") //Optional, defaults to empty string
}
genericVariable {
key("pr_number")
value("\$.number")
expressionType("JSONPath") //Optional, defaults to JSONPath
regexpFilter("") //Optional, defaults to empty string
defaultValue("\$.number") //Optional, defaults to empty string
}
genericVariable {
key("pr_title")
value("\$.pull_request.title")
expressionType("JSONPath") //Optional, defaults to JSONPath
regexpFilter("") //Optional, defaults to empty string
defaultValue("") //Optional, defaults to empty string
}
genericVariable {
key("commits_url")
value("\$.pull_request.commits_url")
expressionType("JSONPath") //Optional, defaults to JSONPath
regexpFilter("") //Optional, defaults to empty string
defaultValue("\$.pull_request.commits_url") //Optional, defaults to empty string
}
genericVariable {
key("pr_labels")
value("\$.pull_request.labels")
expressionType("JSONPath") //Optional, defaults to JSONPath
regexpFilter("") //Optional, defaults to empty string
defaultValue("\$.pull_request.labels") //Optional, defaults to empty string
}
genericVariable {
key("head_branch_name")
value("\$.pull_request.head.ref")
expressionType("JSONPath") //Optional, defaults to JSONPath
regexpFilter("") //Optional, defaults to empty string
defaultValue("") //Optional, defaults to empty string
}
genericVariable {
key("changes_title_from")
value("\$.changes.title.from")
expressionType("JSONPath") //Optional, defaults to JSONPath
regexpFilter("") //Optional, defaults to empty string
defaultValue("") //Optional, defaults to empty string
}
genericVariable {
key("comment_body")
value("\$.comment.body")
expressionType("JSONPath") //Optional, defaults to JSONPath
regexpFilter("Rebuild") //Optional, defaults to empty string
defaultValue("") //Optional, defaults to empty string
}
}
I have tried this solution, if I leave Rebuild in comment, the pipeline will be triggerd, but it needs more information, such as pull reuqest number.
I tried to set defaultValue("")`
just like this:
defaultValue("\$.number") //Optional, defaults to empty string
but it did not work.
any solutions?
``

Related

How to safely unwrap optional variables in dart?

I couldn't find a way to safely unwrap an optional variable as we do in swift
var myString: String?
if let myString = myString {
print(myString) // myString is a string
}
or in Kotlin
var myString: String?
if (myString != null) {
print(myString) // myString is not null
}
// or
myString?.let {
print(it) // myString is not null
}
In Dart I'm having to do the following, which doesn't look good:
String? myString;
if (myString != null) {
print(myString); // myString still an optional
print(myString!); // myString is now a String! (because of the force unwrap)
}
Is there a way to safely unwrap in a clean way like other null-safety languages? Or we have to always force unwrap variables after a null-check?
Your Dart example seems incomplete but it is difficult to say what is wrong without more context. If myString is a local variabel it will be promoted. You can see this example:
void main(){
myMethod(null); // NULL VALUE
myMethod('Some text'); // Non-null value: Some text
}
void myMethod(String? string) {
if (string != null) {
printWithoutNull(string);
} else {
print('NULL VALUE');
}
}
// Method which does not allow null as input
void printWithoutNull(String string) => print('Non-null value: $string');
It is a different story if we are talking about class variables. You can see more about that problem here: Dart null safety doesn't work with class fields
A solution to that problem is to copy the class variable into a local variable in your method and then promote the local variable with a null check.
In general, I will recommend reading the articles on the official Dart website about null safety: https://dart.dev/null-safety
void main(List<String> args) {
var x;
if (x != null) {
// Since you've already checked, the following statement won't give an error.
print(x!);
} else {
print('ERROR');
}
}
I guess this is how you can safely unwrap optionals or variables that can either be null in Dart.

How to create an empty typed list in dart

I am trying to convert this dart file here to use generics and I get the following error when trying to initialize an empty list in constructor.
Constant list literals can't include a type parameter as a type
argument, such as 'T'. Try replacing the type parameter with a
different
How can I create an empty list in this case. Below code can elaboreate my problem even more
old file
enum PostStatus { initial, success, failure }
class PostState extends Equatable {
const PostState({
this.status = PostStatus.initial,
this.posts = const <Post>[],
this.hasReachedMax = false,
});
final PostStatus status;
final List<Post> posts;
final bool hasReachedMax;
PostState copyWith({
PostStatus status,
List<Post> posts,
bool hasReachedMax,
}) {
return PostState(
status: status ?? this.status,
posts: posts ?? this.posts,
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
);
}
#override
List<Object> get props => [status, posts, hasReachedMax];
}
new file
class PagedState<T> extends Equatable {
const PagedState({
this.status = PagedStatus.initial,
this.items = const <T>[], //ERROR HERE
this.hasReachedMax = false,
});
final PagedStatus status;
final List<T> items;
final bool hasReachedMax;
PagedState copyWith({
PagedStatus status,
List<T> items,
bool hasReachedMax,
}) {
return PagedState(
status: status ?? this.status,
items: items ?? this.items,
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
);
}
#override
List<Object> get props => [status, items, hasReachedMax];
}
As the error says, constant list literals can't use a type parameter, so you must use a non-const literal: <T>[].
However, since it's a default argument and default arguments must be constants, that won't work either. You either will need to:
Use a constant sentinel value as the default and replace it with the desired default later:
const PagedState({
List<T> items = null,
this.hasReachedMax = false,
}) : items = items ?? <T>[];
Use const [] without the explicit type parameter and let automatic type conversions do the work for you.

How to set my computerId into primary key?

Here's my code in domain. I wanted to set my computerId into a primary key. But still display on my table(index). Thanks
package com.data
class ComputerInformation {
String computerId;
String computerName;
String status;
String location;
String serial;
String monitorSerial;
String keyboardSerial;
String mouseSerial;
String cpuSerial;
String avrSerial;
String harddiskSerial;
static constraints = {
computerId(unique:true)
computerName(blank:false)
status(blank:false)
location(blank:false)
serial(blank:false)
monitorSerial(blank:false)
keyboardSerial(blank:false)
mouseSerial(blank:false)
cpuSerial(blank:false)
avrSerial(blank:false)
harddiskSerial(blank:false)
}
}
use like this,
static mapping = {
id name: 'computerId'
}
Maybe instead of changing PK, return id as a computerId variable?
package com.data
class ComputerInformation {
String computerName;
String status;
String location;
String serial;
String monitorSerial;
String keyboardSerial;
String mouseSerial;
String cpuSerial;
String avrSerial;
String harddiskSerial;
static constraints = {
computerName(blank:false)
status(blank:false)
location(blank:false)
serial(blank:false)
monitorSerial(blank:false)
keyboardSerial(blank:false)
mouseSerial(blank:false)
cpuSerial(blank:false)
avrSerial(blank:false)
harddiskSerial(blank:false)
}
def getComputerId(){
return id
}
}
Moreover if you need computerId as a String, you can change getComputerId function to:
String getComputerId(){
return id.toString()
}

ConversionErrorInterceptor throws conversion error during quit/cancel (Struts 2)

The scenario of the problem is this
1) We map the struts field values to the dtos. The dtos contain integer fields which again are displayed on the screen.
2) Now I enter an incorrect value which gives conversion error for that integer field.
3) At that point in time I decide to quit the page(i.e press cancel), I get a conversion error. This is because the StrutsConversionErrorInterceptor gets called everytime.
Is there any way that I can skip the strutsConversionErrorInterceptor when I am calling a particular method the way we can skip validation using excludeMethods
Use this code to override Struts's StrutsConversionErrorInterceptor...
public class MyConversionErrorInterceptor extends AbstractInterceptor {
private static final long serialVersionUID = 1L;
public static final String ORIGINAL_PROPERTY_OVERRIDE = "original.property.override";
protected Object getOverrideExpr(ActionInvocation invocation, Object value) {
ValueStack stack = invocation.getStack();
try {
stack.push(value);
return "'" + stack.findValue("top", String.class) + "'";
} finally {
stack.pop();
}
}
#Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext invocationContext = invocation.getInvocationContext();
Map<String, Object> conversionErrors = invocationContext.getConversionErrors();
ValueStack stack = invocationContext.getValueStack();
HashMap<Object, Object> fakie = null;
BaseAction baseAction = (BaseAction) invocation.getAction();
String buttonName = baseAction.getButtonName();
for (Map.Entry<String, Object> entry : conversionErrors.entrySet()) {
String propertyName = entry.getKey();
Object value = entry.getValue();
if (shouldAddError(propertyName, value)) {
String message = XWorkConverter.getConversionErrorMessage(propertyName, stack);
Object action = invocation.getAction();
if (action instanceof ValidationAware) {
ValidationAware va = (ValidationAware) action;
if(buttonName.equalsIgnoreCas("Next")){
va.addFieldError(propertyName, message);
}
}
if (fakie == null) {
fakie = new HashMap<Object, Object>();
}
if(buttonName.equalsIgnoreCas("Next")){
fakie.put(propertyName, getOverrideExpr(invocation, value));
}
}
}
if (fakie != null) {
// if there were some errors, put the original (fake) values in
// place right before the result
stack.getContext().put(ORIGINAL_PROPERTY_OVERRIDE, fakie);
invocation.addPreResultListener(new PreResultListener() {
public void beforeResult(ActionInvocation invocation, String resultCode) {
Map<Object, Object> fakie = (Map<Object, Object>) invocation.getInvocationContext().get(ORIGINAL_PROPERTY_OVERRIDE);
if (fakie != null) {
invocation.getStack().setExprOverrides(fakie);
}
}
});
}
return invocation.invoke();
}
protected boolean shouldAddError(String propertyName, Object value) {
if (value == null) {
return false;
}
if ("".equals(value)) {
return false;
}
if (value instanceof String[]) {
String[] array = (String[]) value;
if (array.length == 0) {
return false;
}
if (array.length > 1) {
return true;
}
String str = array[0];
if ("".equals(str)) {
return false;
}
}
return true;
}
}
You can specify you button names on which you want validation to fire. In above code I have used "Next" in code you can see
if(buttonName.equalsIgnoreCas("Next"))
Yes, you can skip calling the interceptor.
Just remove the interceptor definition from your action definition in struts.xml file.
i.e., remove <interceptor-ref name="conversionError"/>
Mainly this interceptor adds any error found in the ActionContext's conversionErrors map as a field error (provided that the action implements ValidationAware). In addition, any field that contains a validation error has its original value saved such that any subsequent requests for that value return the original value rather than the value in the action. This is important because if the value "abc" is submitted and can't be converted to an int, we want to display the original string ("abc") again rather than the int value (likely 0, which would make very little sense to the user).
After you removed this interceptor, if the struts failed to map the field with parameter of the object(i.e., from string to int), it throws result input action error.
This seems to be a better method to handle this scenario - using Conversion Validator. Repopulating Field upon conversion Error section is something very useful:
http://struts.apache.org/2.0.14/docs/conversion-validator.html

Symfony - Propel - Value is not an integer

in my schema I set the size:
size: { type: bigint, required: true }
My generated 'base' model gives me:
public function setSize($v)
{
if ($v !== null) {
$v = (string) $v;
}
if ($this->size !== $v) {
$this->size = $v;
$this->modifiedColumns[] = TorrentPeer::SIZE;
}
return $this;
} // setSize()
Why does it case it to a string and not an integer?
I now receive the error:
"7818435653" is not an integer.
I tried changing the (string) to (int), but it did not work, I receive the same error. I'm confused why Propel made this value string when I specified bigint. Any help?
propel stores bigint as a string as PHP's integer type is too small: http://www.propelorm.org/wiki/Documentation/1.5/Schema#NumericTypes

Resources