I was trying to configure artifactory in Jenkins using groovy init scripts, this is my script which I'm trying to execute
import jenkins.model.*
import org.jfrog.*
import org.jfrog.hudson.*
import org.jfrog.hudson.util.Credentials;
def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("org.jfrog.hudson.ArtifactoryBuilder")
def deployerCredentials = new Credentials("admin", "password")
def resolverCredentials = new Credentials("", "")
def sinst = [new ArtifactoryServer(
"server-id",
"http://localhost:8081/artifactory",
deployerCredentials,
resolverCredentials,
300,
false,
false,
false,
1)
]
desc.setArtifactoryServers(sinst)
desc.save()
But I was getting the following error
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.jfrog.hudson.CredentialsConfig(java.lang.String, java.lang.String)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1732)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1532)
at org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:49)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:255)
at Script1.run(Script1.groovy:17)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
at hudson.util.RemotingDiagnostics$Script.call(RemotingDiagnostics.java:142)
at hudson.util.RemotingDiagnostics$Script.call(RemotingDiagnostics.java:114)
at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
at hudson.util.RemotingDiagnostics.executeGroovy(RemotingDiagnostics.java:111)
at jenkins.model.Jenkins._doScript(Jenkins.java:4350)
at jenkins.model.Jenkins.doScriptText(Jenkins.java:4328)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:343)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:184)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:117)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:129)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:715)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:845)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
It would be great if anyone could help me figuring out this issue.
this one works for me
//artifactory
import jenkins.model.*
import org.jfrog.*
import org.jfrog.hudson.*
import org.jfrog.hudson.util.Credentials;
inst = Jenkins.getInstance()
desc = inst.getDescriptor("org.jfrog.hudson.ArtifactoryBuilder")
deployerCredentials = new CredentialsConfig("user", "password","1",true)
sinst = [new ArtifactoryServer(
"1",
"https://artifactory-url/",
deployerCredentials,
null,
300,
false ,
3)]
desc.setUseCredentialsPlugin(false)
desc.setArtifactoryServers(sinst)
desc.save()
Related
I am using a condition in my script in the REST endpoint and I am receiving the following errors:
Anyone knows what the problem is and what needs to be fixed?
Here is the code:
package CreateMultipleSubtasks
import org.apache.log4j.Logger
import com.atlassian.jira.plugin.webfragment.model.JiraHelper
import com.atlassian.jira.component.ComponentAccessor
def log1 = Logger.getLogger("atlassian-jira.log")
log1.warn("MOUNA BEFORE")
Configuration_CreateMultipleSubtasks conf = new Configuration_CreateMultipleSubtasks()
def subTaskCreatorHashMap= conf.getSubTaskCreatorHashMap()
String projectKey = subTaskCreatorHashMap["projectKey"];
String issueTypeName = subTaskCreatorHashMap["issueTypeName"];
log.warn("MOUNA PROJECT KEY "+ projectKey+" issuetypename "+issueTypeName)
def val=jiraHelper.project?.key==projectKey && issue.issueType.name==issueTypeName
return val
I am trying to perform a REST endpoint with its corresponding web fragment but I am getting the error:
script function failed on issue: issue: SF-347, user: mouh, fieldId: __init__, file: <inline script>, edit behaviour: https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/8, https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/17, https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/21
Here is my error log here below:
2022-08-16 20:39:37,512+0200 https-openssl-nio-443-exec-278 ERROR mouh 1239x60320x27 mu7qce 10.248.27.109 /rest/scriptrunner/behaviours/latest/validators.json [c.o.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: issue: SF-347, user: mouh, fieldId: __init__, file: <inline script>, edit behaviour: https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/8, https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/17, https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/21
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" took 0 ms
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" - "green" -0
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" took 0 ms
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" - "yellow" -0
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" took 0 ms
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" - "red" -0
I don't understand why I have this error my code is super simple. Here is the way in which I have created my web fragment:
This is a screenshot of the custom web item fragment I have created:
This is the corresponding REST endpoint I have created:
I am specifying the file MounaBulkSummary.groovy to be the one containing the code for the REST endpoint.
Here is the content of the file MounaBulkSummary.groovy
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
def log = Logger.warn("atlassian-jira.log")
log.warn("MOUNA BULK")
#BaseScript CustomEndpointDelegate delegate
MounaBulkSummary(httpMethod: "GET") { MultivaluedMap queryParams ->
log.warn("MOUNA BULK")
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
def issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)
def baseUrl = ScriptRunnerImpl.getOsgiService(ApplicationProperties).getBaseUrl(UrlMode.ABSOLUTE)
def redirectUrl = "https://secapps.eur.ad.sag:9888/FPIA/?iTrac=${issue.key}&reporter=${user.key}&baseURL=${baseUrl}"
Response.temporaryRedirect(URI.create(redirectUrl)).build()
}
I found my mistake, I needed to use call in the URL. Here is the code for the REST API:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
#BaseScript CustomEndpointDelegate delegate
def log = Logger.getLogger("atlassian-jira.log")
long iTracSuperFeatureSummaryUpdaterIssueTypeID= 10200;
int iTracSuperFeatureSummaryUpdaterProjectID= 23520;
String iTracSuperFeatureSummaryUpdaterURL= "http://itrac-service:8080/bulksummaryupdater/bulksplitter?key=:1:&reporter=:2:";
callMounaBulkSummary(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->
log.warn("MOUNA BULK")
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
Issue issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)
def project = issue.getProject()
def baseUrl = ScriptRunnerImpl.getOsgiService(ApplicationProperties).getBaseUrl(UrlMode.ABSOLUTE)
log.warn("MOUNA BULK "+user+" "+issue+" "+baseUrl+" "+project +" "+project.get("id"))
iTracSuperFeatureSummaryUpdaterURL= iTracSuperFeatureSummaryUpdaterURL.replaceAll(":1:", issue.getKey())
iTracSuperFeatureSummaryUpdaterURL= iTracSuperFeatureSummaryUpdaterURL.replaceAll(":2:", user.getUsername())
def projectID=project.get("id")
int projectIDInt= projectID as int
if(iTracSuperFeatureSummaryUpdaterProjectID== projectIDInt && iTracSuperFeatureSummaryUpdaterIssueTypeID==Long.valueOf(issue.getIssueTypeId()) ){
Response.temporaryRedirect(URI.create(iTracSuperFeatureSummaryUpdaterURL)).build()
}
}
Other code for as similar REST endpoint:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
#BaseScript CustomEndpointDelegate delegate
def log = Logger.getLogger("atlassian-jira.log")
int iTracSuperFeatureSplitterIssueTypeID= 10200;
int iTracSuperFeatureSplitterProjectID= 23520;
String iTracSuperFeatureSplitterURL= "http://itrac-service:8080/featuregenerator/bulksplitter?key=:1:&reporter=:2:";
callMounaBulkSplitter(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->
log.warn("MOUNA BULK")
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
Issue issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)
def project = issue.getProject()
def baseUrl = ScriptRunnerImpl.getOsgiService(ApplicationProperties).getBaseUrl(UrlMode.ABSOLUTE)
log.warn("MOUNA BULK "+user+" "+issue+" "+baseUrl+" "+project +" "+project.get("id"))
iTracSuperFeatureSplitterURL= iTracSuperFeatureSplitterURL.replaceAll(":1:", issue.getKey())
iTracSuperFeatureSplitterURL= iTracSuperFeatureSplitterURL.replaceAll(":2:", user.getUsername())
def projectID=project.get("id")
int projectIDInt= projectID as int
if(iTracSuperFeatureSplitterProjectID== projectIDInt && iTracSuperFeatureSplitterIssueTypeID==Long.valueOf(issue.getIssueTypeId()) ){
Response.temporaryRedirect(URI.create(iTracSuperFeatureSplitterURL)).build()
}
}
I am looking for a Groovy script that can create a masked password pair in Jenkins.
I've tried the following but it doesn't work.
import java.util.logging.Logger
import jenkins.model.*
import hudson.logging.*
//import com.michelin.cio.hudson.plugins.maskpasswords.*
import com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsConfig
import com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsBuildWrapper.VarPasswordPair
maskPasswordsConfig = MaskPasswordsConfig.getInstance()
varPasswordPairs = maskPasswordsConfig.getGlobalVarPasswordPairs()
MaskPasswordsConfig plugin = new MaskPasswordsConfig()
VarPasswordPair pwdPair = new VarPasswordPair("PWD", "myPassword")
plugin.addGlobalVarPasswordPair(pwdPair)
plugin.save()
I'm getting no results in the script console. Any help is appreciated.
#mweish, Just come across your post as I was trying to setup something similar, this should do what you are looking for:
import java.util.logging.Logger
import com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsConfig
import com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsBuildWrapper.VarPasswordPair
import jenkins.model.*
import hudson.logging.*
Logger logger = Logger.getLogger("")
Jenkins jenkins = Jenkins.getInstance()
MaskPasswordsConfig plugin = new MaskPasswordsConfig()
MASKED_PARAMETER_CLASSES = [
'com.michelin.cio.hudson.plugins.passwordparam.PasswordParameterDefinition',
'hudson.model.PasswordParameterDefinition'
]
def NAME_PASSWORD_PAIRS = [
[NAME:'PWD', PASSWORD:'myPassword']
]
// Add classes that should automatically be masked
MASKED_PARAMETER_CLASSES.each { maskedClass ->
plugin.addMaskedPasswordParameterDefinition(maskedClass)
}
// Add Global name/password pairs
NAME_PASSWORD_PAIRS.each { namePassPair ->
VarPasswordPair passwordPair = new VarPasswordPair(namePassPair.NAME, namePassPair.PASSWORD)
plugin.addGlobalVarPasswordPair(passwordPair)
}
plugin.save(plugin)
logger.info('Successfully Configured the Mask Passwords plugin')
I am using the below code :
===============================================
from datetime import timedelta, datetime
from airflow import DAG
from airflow.contrib.operators.dataflow_operator import DataflowTemplateOperator
from airflow.operators.dummy_operator import DummyOperator
from airflow.models import Variable
PROJECT = Variable.get('gcp_project')
print("project"+PROJECT)
TEMP_BUCKET = Variable.get('stg_bucket')
TEMPLATE = "gs://*************"
INPUT_FILE = "{\"location1\":\"test:random.Summary\"}"
OUTPUT_FILE = "{\"location1\":\"test:random.TestSummary\"}"
PARAMETERS = {
'inputFile': INPUT_FILE,
'outputFile': OUTPUT_FILE
}
TODAY = datetime.today()
TODAY_STRING = datetime.today().strftime('%Y%m%d')
DEFAULT_DAG_ARGS = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': TODAY,
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
'schedule_interval': '#hourly',
'dataflow_default_options': {
'project': PROJECT,
'region':'us-west1',
'zone': 'us-west1-b',
'tempLocation': TEMP_BUCKET
}
}
dag = DAG(
'Demo-DAG-DataflowTemplate',
default_args=DEFAULT_DAG_ARGS,
dagrun_timeout=timedelta(hours=1)
)
start = DummyOperator(task_id='inicio', dag=dag)
end = DummyOperator(task_id='fim', dag=dag)
t1 = DataflowTemplateOperator(
task_id='dataflow_template_launch',
template=TEMPLATE,
parameters=PARAMETERS,
dag=dag)
start >> t1 >> end
====================================================================================================
However, I am getting issue while running the DAG. The error says:
returned "The template parameters are invalid."
I am able to run the same template using normal python code but when I am using the DataflowTemplateOperator , its not executing. Can some one please help me on this?
My approach:
import hudson.plugins.audit_trail.AuditTrailPlugin
import hudson.plugins.jobConfigHistory.JobConfigHistory
import net.sf.json.JSONObject
def auditTrialPlugin = Jenkins.getInstance().getPlugin(AuditTrailPlugin.class)
// println(auditTrialPlugin.getConfigXml().asString())
println("Going to configure...")
def logger = new JSONObject()
logger.put("log", "Vibin")
logger.put("limit", "1")
logger.put("count", "2")
logger.put("stapler-class", "hudson.plugins.audit_trail.LogFileAuditLogger")
logger.put("\$class", "hudson.plugins.audit_trail.LogFileAuditLogger")
def plugin = new JSONObject()
plugin.put("name", "audit-trail")
plugin.put("pattern", "")
plugin.put("logBuildCause", true)
plugin.put("loggers", logger)
auditTrialPlugin.configure(null, plugin)
Error happening:
java.lang.NoSuchMethodException: hudson.plugins.audit_trail.LogFileAuditLogger.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
Caused: java.lang.InstantiationException: hudson.plugins.audit_trail.LogFileAuditLogger
at java.lang.Class.newInstance(Class.java:427)
at hudson.model.Descriptor.newInstance(Descriptor.java:578)
Caused: java.lang.Error: Failed to instantiate class hudson.plugins.audit_trail.LogFileAuditLogger from {"log":"Vibin","limit":"1","count":"2","stapler-class":"hudson.plugins.audit_trail.LogFileAuditLogger","$class":"hudson.plugins.audit_trail.LogFileAuditLogger"}
at hudson.model.Descriptor.newInstance(Descriptor.java:600)
at hudson.model.Descriptor.newInstancesFromHeteroList(Descriptor.java:1055)
at hudson.model.Descriptor.newInstancesFromHeteroList(Descriptor.java:1017)
at hudson.plugins.audit_trail.AuditTrailPlugin.configure(AuditTrailPlugin.java:78)
at hudson.plugins.audit_trail.AuditTrailPlugin$configure$1.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at Script1.run(Script1.groovy:24)
I tried to follow the code base of the plugin which I found on GitHub. There is a 'configure' function for the plugin which I tried to use which isn't working.
Codebase of plugin: GitHub link
Try this:
import jenkins.model.*;
import hudson.plugins.audit_trail.AuditTrailPlugin;
import hudson.plugins.audit_trail.LogFileAuditLogger;
def log = "Vibin"
def limit = 1
def count = 2
LogFileAuditLogger logFileAuditLogger = new LogFileAuditLogger(log, limit, count)
Jenkins j = Jenkins.getInstance();
AuditTrailPlugin plugin = j.getPlugin(AuditTrailPlugin.class);
plugin.loggers.clear()
plugin.loggers.add(logFileAuditLogger)
plugin.pattern = "" // empty pattern?
plugin.save()
plugin.start()
I think using LogFileAuditLogger class is more clear than 'configure' function.