Skip to content

Commit 675b326

Browse files
MarkDeMariaMark DeMaria
authored and
Mark DeMaria
committed
Allow editing of build hooks on build configuration page
-Single-select tag for Command, Script, and Args, Command+Args, Script+Args -Whatever option is currently-selected upon hitting 'Save' will overwrite anything else. For example, if post commit has a command in it, and you hit save on the Args page, the command will be deleted and the args saved. -Checkbox shows/hides the build hook editor. Leaving it unchcked and selecting "Save" with anything saved in the post commit section of the YAML will be deleted, as the user has indicated they do not wish to have any build hooks
1 parent 32c3a25 commit 675b326

File tree

5 files changed

+268
-34
lines changed

5 files changed

+268
-34
lines changed

app/scripts/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ window.OPENSHIFT_CONSTANTS = {
5151
"builds": "architecture/core_concepts/builds_and_image_streams.html#builds",
5252
"image-streams": "architecture/core_concepts/builds_and_image_streams.html#image-streams",
5353
"storage": "architecture/additional_concepts/storage.html",
54+
"build-hooks": "https://docs.openshift.org/latest/dev_guide/builds.html#build-hooks",
5455
// default should remain last, add new links above
5556
"default": "welcome/index.html"
5657
},

app/scripts/controllers/edit/buildConfig.js

+76-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ angular.module('openshiftConsole')
5555
"title": "Inline"
5656
}];
5757
$scope.view = {
58-
advancedOptions: false
58+
advancedOptions: false,
59+
hasHooks: false
5960
};
6061
$scope.breadcrumbs = [
6162
{
@@ -117,6 +118,76 @@ angular.module('openshiftConsole')
117118
"SerialLatestOnly"
118119
];
119120

121+
$scope.buildHookTypes = [{
122+
"id": "script",
123+
"label": "Shell Script"
124+
}, {
125+
"id": "command",
126+
"label": "Command"
127+
}, {
128+
"id": "args",
129+
"label": "Arguments to Default Image Entry Point"
130+
}, {
131+
"id": "scriptArgs",
132+
"label": "Shell Script with Arguments"
133+
}, {
134+
"id": "commandArgs",
135+
"label": "Command with Arguments"
136+
}];
137+
138+
$scope.buildHookSelection = {
139+
"type": {}
140+
};
141+
142+
var getInitialBuildHookSelection = function() {
143+
$scope.view.hasHooks = (_.size($scope.buildConfig.spec.postCommit.args) ||
144+
_.size($scope.buildConfig.spec.postCommit.command) ||
145+
$scope.buildConfig.spec.postCommit.script) ? true : false;
146+
147+
if (_.size($scope.buildConfig.spec.postCommit.args) && _.size($scope.buildConfig.spec.postCommit.command)) {
148+
$scope.buildHookSelection.type.id = "commandArgs";
149+
} else if ($scope.buildConfig.spec.postCommit.script && _.size($scope.buildConfig.spec.postCommit.args)) {
150+
$scope.buildHookSelection.type.id = "scriptArgs";
151+
} else if (_.size($scope.buildConfig.spec.postCommit.args)) {
152+
$scope.buildHookSelection.type.id = "args";
153+
} else if ($scope.buildConfig.spec.postCommit.script) {
154+
$scope.buildHookSelection.type.id = "script";
155+
} else {
156+
$scope.buildHookSelection.type.id = "command";
157+
}
158+
159+
$scope.buildHookSelection.type.label = _.find($scope.buildHookTypes, {'id': $scope.buildHookSelection.type.id}).label;
160+
};
161+
162+
var clearIncompatibleBuildHookFields = function(selectedBuildHookID) {
163+
if ($scope.view.hasHooks) {
164+
switch (selectedBuildHookID) {
165+
case "script":
166+
$scope.updatedBuildConfig.spec.postCommit.command = [];
167+
$scope.updatedBuildConfig.spec.postCommit.args = [];
168+
break;
169+
case "command":
170+
$scope.updatedBuildConfig.spec.postCommit.script = "";
171+
$scope.updatedBuildConfig.spec.postCommit.args = [];
172+
break;
173+
case "args":
174+
$scope.updatedBuildConfig.spec.postCommit.script = "";
175+
$scope.updatedBuildConfig.spec.postCommit.command = [];
176+
break;
177+
case "scriptArgs":
178+
$scope.updatedBuildConfig.spec.postCommit.command = [];
179+
break;
180+
case "commandArgs":
181+
$scope.updatedBuildConfig.spec.postCommit.script = "";
182+
break;
183+
}
184+
} else {
185+
$scope.updatedBuildConfig.spec.postCommit.command = [];
186+
$scope.updatedBuildConfig.spec.postCommit.args = [];
187+
$scope.updatedBuildConfig.spec.postCommit.script = "";
188+
}
189+
};
190+
120191
AlertMessageService.getAlerts().forEach(function(alert) {
121192
$scope.alerts[alert.name] = alert.data;
122193
});
@@ -143,6 +214,8 @@ angular.module('openshiftConsole')
143214
// success
144215
function(buildConfig) {
145216
$scope.buildConfig = buildConfig;
217+
getInitialBuildHookSelection();
218+
146219
$scope.updatedBuildConfig = angular.copy($scope.buildConfig);
147220
$scope.buildStrategy = buildStrategy($scope.updatedBuildConfig);
148221
$scope.strategyType = $scope.buildConfig.spec.strategy.type;
@@ -180,7 +253,7 @@ angular.module('openshiftConsole')
180253
}
181254

182255
if (imageOptions.type === "ImageStreamImage") {
183-
isimage = (imageData.namespace || buildConfig.metadata.namespace) + "/" + imageData.name;
256+
isimage = (imageData.namespace || buildConfig.metadata.namespace) + "/" + imageData.name;
184257
} else {
185258
isimage = "";
186259
}
@@ -414,6 +487,7 @@ angular.module('openshiftConsole')
414487

415488
$scope.save = function() {
416489
$scope.disableInputs = true;
490+
clearIncompatibleBuildHookFields($scope.buildHookSelection.type.id);
417491
// Update Configuration
418492
buildStrategy($scope.updatedBuildConfig).forcePull = $scope.options.forcePull;
419493

app/views/edit/build-config.html

+67-5
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ <h3 class="with-divider">Image Configuration</h3>
411411
</dl>
412412
</div>
413413

414-
415-
416414
<div ng-if="!(updatedBuildConfig | isJenkinsPipelineStrategy)" class="section">
417415
<h3 class="with-divider">Environment Variables<span class="help action-inline">
418416
<a href="">
@@ -518,8 +516,8 @@ <h3 class="with-divider">Run Policy
518516
{{type | sentenceCase}}
519517
</ui-select-choices>
520518
</ui-select>
521-
522519
</div>
520+
523521
<div ng-switch="updatedBuildConfig.spec.runPolicy">
524522
<div class="help-block" ng-switch-when="Serial">Builds triggered from this Build Configuration will run one at the time, in the order they have been triggered.</div>
525523
<div class="help-block" ng-switch-when="Parallel">Builds triggered from this Build Configuration will run all at the same time. The order in which they will finish is not guaranteed.</div>
@@ -528,8 +526,72 @@ <h3 class="with-divider">Run Policy
528526
</div>
529527
</div>
530528

531-
<div>
532-
<a href="" ng-click="view.advancedOptions = !view.advancedOptions" role="button">{{view.advancedOptions ? 'Hide' : 'Show'}} Advanced Options</a>
529+
<div ng-if="view.advancedOptions && !(updatedBuildConfig | isJenkinsPipelineStrategy)" class="section">
530+
<h3 class="with-divider">Build Hooks
531+
<span class="help action-inline">
532+
<a href="{{'build-hooks' | helpLink}}" aria-hidden="true" target="_blank"><span class="learn-more-inline">Learn more&nbsp;<i class="fa fa-external-link"></i></span></a>
533+
</span>
534+
</h3>
535+
536+
<div class="checkbox">
537+
<label>
538+
<input type="checkbox" ng-model="view.hasHooks" id="enable-build-hooks">
539+
Run build hooks after image is built
540+
</label>
541+
<div class="help-block">
542+
Build hooks allow you to run commands at the end of the build to verify the image.
543+
</div>
544+
</div>
545+
546+
<div ng-show="view.hasHooks">
547+
<div class="form-group">
548+
<h4>Hook Types</h4>
549+
<ui-select
550+
ng-model="buildHookSelection.type"
551+
title="Choose a type of build hook">
552+
<ui-select-match>{{$select.selected.label}}</ui-select-match>
553+
<ui-select-choices repeat="type in buildHookTypes">
554+
{{type.label}}
555+
</ui-select-choices>
556+
</ui-select>
557+
</div>
558+
559+
<fieldset>
560+
<div ng-show="buildHookSelection.type.id === 'script' || buildHookSelection.type.id === 'scriptArgs'">
561+
<h4>Script</h4>
562+
<div
563+
ui-ace="{
564+
mode: 'sh',
565+
theme: 'eclipse',
566+
rendererOptions: {
567+
fadeFoldWidgets: true,
568+
showPrintMargin: false
569+
}
570+
}"
571+
ng-model="updatedBuildConfig.spec.postCommit.script"
572+
class="ace-bordered ace-inline mar-top-md">
573+
</div>
574+
</div>
575+
576+
<div ng-show="buildHookSelection.type.id === 'command' || buildHookSelection.type.id === 'commandArgs'">
577+
<h4>Command</h4>
578+
<edit-command
579+
args="updatedBuildConfig.spec.postCommit.command">
580+
</edit-command>
581+
</div>
582+
583+
<div ng-show="buildHookSelection.type.id === 'args' || buildHookSelection.type.id === 'commandArgs' || buildHookSelection.type.id === 'scriptArgs' ">
584+
<h4>Arguments</h4>
585+
<edit-command
586+
args="updatedBuildConfig.spec.postCommit.args">
587+
</edit-command>
588+
</div>
589+
</fieldset>
590+
</div>
591+
</div>
592+
593+
<div class="gutter-top">
594+
<a href="" ng-click="view.advancedOptions = !view.advancedOptions" role="button">{{view.advancedOptions ? 'Hide' : 'Show'}} advanced options</a>
533595
</div>
534596
<div class="buttons gutter-top-bottom">
535597
<button

0 commit comments

Comments
 (0)