Jenkins Job DSL: how do you set "Default subview"? - jenkins-job-dsl

I am trying to create nested tabs with a Jenkins Job DSL Groovy script. It creates them, but I can find no way to set the "Default subview" in the DSL API. It does not appear to display the tabs correctly until I do this. Once I manually, change that default, it displays correctly. Here is the code:
nestedView(viewName) {
views {
listView("Builds (Staging)") {
jobs {
name(buildJobName)
}
columns {
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
}
}
listView("Deployments (Staging)") {
jobs {
name(deployJobName)
}
columns {
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
}
}
}
}
Original view
Corrected view after manually changing Default subview in Edit View

You can use a Configure Block to any missing config XML elements.
nestedView('test') {
views {
listView("Builds (Staging)") {
jobs {
name('foo')
}
columns {
status()
weather()
name()
}
}
listView("Deployments (Staging)") {
jobs {
name('bar')
}
columns {
status()
weather()
name()
}
}
}
configure { view ->
view / defaultView('Builds (Staging)')
}
}
Please file a ticket or open a pull request for any missing DSL methods.

If you happen to be configuring views under a folder, you can set it there.
folder(abc)
{
views {
listView('foo') {
primaryView('foo')
}
}
It looks like it's available since version 1.36

Related

Cannot read property 'node' of undefined while npm run build

I have the method which gets data from contentful using graphql and returns some data:
exports.getMetadata = async (graphql, reporter, query) => {
const result = await graphql(query)
if (result.errors) {
reporter.panicOnBuild("Error while running medatada GraphQL query")
}
const {
data: {
allContentfulPages: {
edges: {
0: {
node: { meta, opengraph },
},
},
},
},
} = result
const metaJson = JSON.parse(meta.internal.content)
const opengraphJson = JSON.parse(opengraph.internal.content)
return { metaJson, opengraphJson }
}
that's how graphql query looks:
query {
# since our Contentful has enabled "locales", but pages slug doesn't need it, get only default language data
allContentfulPages(filter: { node_locale: { eq: "en-US" }, slug:{eq: "insights"} }) {
edges {
node {
meta {
internal {
content
}
}
opengraph {
internal {
content
}
}
}
}
}
}
when i start project executing npm run develop everything works fine and i don't have any error in console but while building npm run build i get TypeError: Cannot read property 'node' of undefined i tried to add statement like if result !== null ... and if result....edges[0].node !== null in many variants it didn't work, application all time breaks in one place. Please help me to figure out what;s going on ?
Too much [unguarded/unconditional] decomposition... stop at must exist node:
const { data: { allContentfulPages: { edges }}} = result;
if( edges && edges[0] ) {
return {
metaJson: JSON.parse(edges[0].node.meta.internal.content),
opengraphJson: JSON.parse(edges[0].node.opengraph.internal.content)
};

Pass multiple InputPaths to a StepFunctions Task

While invoking a state's task, is it possible to specify multiple InputPaths, or 'pick' more than one JSON nodes to be passed to the task's input ?
Example:
If this is the execution input:
{
"id":"identifier",
"nestedObjectA": {
"doubleNestedObjectA": {
"valueA": "value"
}
},
"nestedObjectB" : {
"valueB": "value"
}
}
is it possible to pass the following as input to one task:
{
"id":"identifier",
"nestedObjectB" : {
"valueB": "value"
}
}
and the following to other ?
{
"id":"identifier",
"nestedObjectA": {
"doubleNestedObjectA": {
"valueA": "value"
}
}
}
This was not initially possible using JsonPath, but can now be easily done using parameters in stepfunctions.

Jenkins Job DSL: Creating parameter object in function

I want to write a function (in a jenkins job DSL) which returns a reusable set of parameters for job defintions. Like this:
def pars(name) {
return parameters {
booleanParam(name, true)
}
}
pipelineJob("Test1") {
pars("name")
}
pipelineJob("Test2") {
pars("name2")
}
This does not work, but can I somehow rewrite the example so that it does work?
parameters can not be called in your helper method, but you can create a closure in a helper method.
Try this:
def pars(name) {
return {
booleanParam(name, true)
}
}
pipelineJob("Test1") {
parameters pars("name")
}
Or this:
def pars(name) {
return {
parameters {
booleanParam(name, true)
}
}
}
pipelineJob("Test1").with pars("name")

Ember CLI -- store.find doesn't work when searching for all results with a given name

I'm trying to search for all employees that have a title of developer
As per the documentation (http://guides.emberjs.com/v1.10.0/models/finding-records/) It seems the correct way to do this is:
return this.store.find('employee', { title: "developer" });
But this is not working in Ember CLI 0.2.2, and I can't even see my template when I try this, even though when I do
return this.store.find('employee')
I can see a list of all employees and there are multiple employees with that title
Turns out I needed to override the DS.FixtureAdapter::queryFixtures method. I went into my adapters/application.js file and added
queryFixtures: function(records, query, type) {
return records.filter(function(record) {
for(var key in query) {
if (!query.hasOwnProperty(key)) { continue; }
var value = query[key];
if (record[key] !== value) { return false; }
}
return true;
});
}

How can I stop archiving (scheduled) of referenced item in Sitecore?

When I manually archive an item which is referenced by other items Sitecore popup dialog box with Actions – how to handle the links.
If the item is configured for automatic archiving with “Set Archive Date” and it is archived seems that Sitecore is choosing by default “Leave Links” action, so all links to the archived item will be broken.
How/Where could I hooked up in order to stop archiving of item (scheduled archiving) which is referenced by other items? I would like to stop archiving and create some rapport that that archiving was not successful.
In order to prevent Sitecore from archiving linked items, you need to overrider 2 classes.
First of them is ArchiveItem so it's checking whether item is linked before archiving it:
namespace My.Assembly.And.Namespace
{
public class MyArchiveItem : Sitecore.Tasks.ArchiveItem
{
public MyArchiveItem(System.DateTime taskDate) : base(taskDate)
{
}
public override void Execute()
{
using (new Sitecore.SecurityModel.SecurityDisabler())
{
lock (SyncRoot)
{
Sitecore.Data.Items.Item item = GetItem();
if (item != null && HasLink(Sitecore.Globals.LinkDatabase, item))
{
Sitecore.Diagnostics.Log.Error(string.Format(
"Item {0} or one of its descendants are linked from other items. "
+ "Remove link before scheduling archive.", item.Paths.FullPath), this);
// uncomment next line if you don't want to retry archiving attempt
//Sitecore.Globals.TaskDatabase.Remove(this);
return;
}
}
}
base.Execute();
}
private static bool HasLink(Sitecore.Links.LinkDatabase linkDatabase, Sitecore.Data.Items.Item item)
{
Sitecore.Links.ItemLink[] referrers = linkDatabase.GetReferrers(item);
if (referrers.Length > 0)
{
if (referrers.Any(link => link.SourceFieldID != Sitecore.FieldIDs.Source))
{
return true;
}
}
foreach (Sitecore.Data.Items.Item item2 in item.Children)
{
if (HasLink(linkDatabase, item2))
{
return true;
}
}
return false;
}
}
}
Second class which you need to override is SqlServerTaskDatabase so it schedules the overriden MyArchiveItem task instead of the original Sitecore ArchiveItem:
namespace My.Assembly.And.Namespace
{
public class MySqlServerTaskDatabase : Sitecore.Data.SqlServer.SqlServerTaskDatabase
{
public MySqlServerTaskDatabase(string connectionString) : base(connectionString)
{
}
public override void UpdateItemTask(Sitecore.Tasks.Task task, bool insertIfNotFound)
{
Sitecore.Data.Sql.SqlBatch batch = new Sitecore.Data.Sql.SqlBatch(true);
BindTaskData(task, batch);
string sql = GetUpdateSql() +
" WHERE [ItemID] = #itemID AND [Database] = #databaseName AND [taskType] = #taskType";
batch.AddSql(sql);
if (insertIfNotFound)
{
AddInsertTask(batch, true);
}
batch.Execute(ConnectionString);
}
protected new virtual void BindTaskData(Sitecore.Tasks.Task task,
Sitecore.Data.Sql.SqlBatch batch)
{
System.DateTime taskDate = task.TaskDate;
if (taskDate == System.DateTime.MinValue)
{
taskDate = (System.DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
}
batch.AddParameter("taskID", task.ID);
batch.AddParameter("nextRun", taskDate);
if (task is Sitecore.Tasks.ArchiveItem)
{
batch.AddParameter("taskType",
Sitecore.Reflection.ReflectionUtil.GetTypeString(typeof(MyArchiveItem)));
}
else
{
batch.AddParameter("taskType", ReflectionUtil.GetTypeString(task.GetType()));
}
batch.AddParameter("parameters", task.Parameters);
batch.AddParameter("recurrence", task.RecurrencePattern);
batch.AddParameter("itemID", task.ItemID);
batch.AddParameter("databaseName", task.DatabaseName);
if (string.IsNullOrEmpty(task.InstanceName))
{
batch.AddParameter("instanceName", System.DBNull.Value);
}
else
{
batch.AddParameter("instanceName", task.InstanceName);
}
}
}
}
The last thing you need to do is to update Sitecore config to point at MySqlServerTaskDatabase:
<TaskDatabase type="My.Assembly.And.Namespace.MySqlServerTaskDatabase, My.Assembly">
<param connectionStringName="core"/>
</TaskDatabase>
The information about failed archiving attempt will be stored in log files. You may want to update this part to store it in your custom reports.
Below goes additional information which is not necessary for your original problem to work.
You can also hook before the schedule is set as described below to inform user that the item won't be archived.
First create the class that will override ArchiveDateForm class:
namespace My.Assembly.And.Namespace
{
public class MyArchiveDateForm
: Sitecore.Shell.Applications.Dialogs.ArchiveDate.ArchiveDateForm
{
protected override bool SetItemArchiveDate
(Sitecore.Data.Items.Item item, string value)
{
if (HasLink(Sitecore.Globals.LinkDatabase, item))
{
Sitecore.Web.UI.Sheer.SheerResponse.Alert(
"Item or one of its descendants are linked from other items. "
+ "Remove link before scheduling archive.", new string[0]);
return false;
}
return base.SetItemArchiveDate(item, value);
}
private static bool HasLink(Sitecore.Links.LinkDatabase linkDatabase,
Sitecore.Data.Items.Item item)
{
Sitecore.Links.ItemLink[] referrers =
linkDatabase.GetReferrers(item);
if (referrers.Length > 0)
{
if (referrers.Any(
link => link.SourceFieldID != Sitecore.FieldIDs.Source))
{
return true;
}
}
foreach (Sitecore.Data.Items.Item item2 in item.Children)
{
if (HasLink(linkDatabase, item2))
{
return true;
}
}
return false;
}
}
}
Then find the file /sitecore/shell/applications/dialogs/archive item/archive date.xml. Change the 6th line to point at the new class:
<CodeBeside Type="My.Assembly.And.Namespace.MyArchiveDateForm,My.Assembly" />
And that's it. Whenever one will try to schedule archiving of an linked item, Sitecore will display information that the item cannot be archived.