@@ -17,6 +17,7 @@ limitations under the License.
17
17
package main
18
18
19
19
import (
20
+ "context"
20
21
"encoding/json"
21
22
"errors"
22
23
"flag"
@@ -32,7 +33,6 @@ import (
32
33
"github.com/tektoncd/pipeline/cmd/entrypoint/subcommands"
33
34
featureFlags "github.com/tektoncd/pipeline/pkg/apis/config"
34
35
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
35
- v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
36
36
"github.com/tektoncd/pipeline/pkg/credentials"
37
37
"github.com/tektoncd/pipeline/pkg/credentials/dockercreds"
38
38
"github.com/tektoncd/pipeline/pkg/credentials/gitcreds"
@@ -50,12 +50,10 @@ var (
50
50
terminationPath = flag .String ("termination_path" , "/tekton/termination" , "If specified, file to write upon termination" )
51
51
results = flag .String ("results" , "" , "If specified, list of file names that might contain task results" )
52
52
stepResults = flag .String ("step_results" , "" , "step results if specified" )
53
- whenExpressions = flag .String ("when_expressions" , "" , "when expressions if specified" )
54
53
timeout = flag .Duration ("timeout" , time .Duration (0 ), "If specified, sets timeout for step" )
55
54
stdoutPath = flag .String ("stdout_path" , "" , "If specified, file to copy stdout to" )
56
55
stderrPath = flag .String ("stderr_path" , "" , "If specified, file to copy stderr to" )
57
56
breakpointOnFailure = flag .Bool ("breakpoint_on_failure" , false , "If specified, expect steps to not skip on failure" )
58
- debugBeforeStep = flag .Bool ("debug_before_step" , false , "If specified, wait for a debugger to attach before executing the step" )
59
57
onError = flag .String ("on_error" , "" , "Set to \" continue\" to ignore an error and continue when a container terminates with a non-zero exit code." +
60
58
" Set to \" stopAndFail\" to declare a failure with a step error and stop executing the rest of the steps." )
61
59
stepMetadataDir = flag .String ("step_metadata_dir" , "" , "If specified, create directory to store the step metadata e.g. /tekton/steps/<step-name>/" )
66
64
67
65
const (
68
66
defaultWaitPollingInterval = time .Second
67
+ breakpointExitSuffix = ".breakpointexit"
69
68
)
70
69
70
+ func checkForBreakpointOnFailure (e entrypoint.Entrypointer , breakpointExitPostFile string ) {
71
+ if e .BreakpointOnFailure {
72
+ if waitErr := e .Waiter .Wait (context .Background (), breakpointExitPostFile , false , false ); waitErr != nil {
73
+ log .Println ("error occurred while waiting for " + breakpointExitPostFile + " : " + waitErr .Error ())
74
+ }
75
+ // get exitcode from .breakpointexit
76
+ exitCode , readErr := e .BreakpointExitCode (breakpointExitPostFile )
77
+ // if readErr exists, the exitcode with default to 0 as we would like
78
+ // to encourage to continue running the next steps in the taskRun
79
+ if readErr != nil {
80
+ log .Println ("error occurred while reading breakpoint exit code : " + readErr .Error ())
81
+ }
82
+ os .Exit (exitCode )
83
+ }
84
+ }
85
+
71
86
func main () {
72
87
// Add credential flags originally introduced with our legacy credentials helper
73
88
// image (creds-init).
@@ -123,12 +138,6 @@ func main() {
123
138
log .Fatal (err )
124
139
}
125
140
}
126
- var when v1.StepWhenExpressions
127
- if len (* whenExpressions ) > 0 {
128
- if err := json .Unmarshal ([]byte (* whenExpressions ), & when ); err != nil {
129
- log .Fatal (err )
130
- }
131
- }
132
141
133
142
var spireWorkloadAPI spire.EntrypointerAPIClient
134
143
if enableSpire != nil && * enableSpire && socketPath != nil && * socketPath != "" {
@@ -153,9 +162,7 @@ func main() {
153
162
Results : strings .Split (* results , "," ),
154
163
StepResults : strings .Split (* stepResults , "," ),
155
164
Timeout : timeout ,
156
- StepWhenExpressions : when ,
157
165
BreakpointOnFailure : * breakpointOnFailure ,
158
- DebugBeforeStep : * debugBeforeStep ,
159
166
OnError : * onError ,
160
167
StepMetadataDir : * stepMetadataDir ,
161
168
SpireWorkloadAPI : spireWorkloadAPI ,
@@ -169,10 +176,8 @@ func main() {
169
176
}
170
177
171
178
if err := e .Go (); err != nil {
179
+ breakpointExitPostFile := e .PostFile + breakpointExitSuffix
172
180
switch t := err .(type ) { //nolint:errorlint // checking for multiple types with errors.As is ugly.
173
- case entrypoint.DebugBeforeStepError :
174
- log .Println ("Skipping execute step script because before step breakpoint fail-continue" )
175
- os .Exit (1 )
176
181
case entrypoint.SkipError :
177
182
log .Print ("Skipping step because a previous step failed" )
178
183
os .Exit (1 )
@@ -196,7 +201,7 @@ func main() {
196
201
// in both cases has an ExitStatus() method with the
197
202
// same signature.
198
203
if status , ok := t .Sys ().(syscall.WaitStatus ); ok {
199
- e . CheckForBreakpointOnFailure ( )
204
+ checkForBreakpointOnFailure ( e , breakpointExitPostFile )
200
205
// ignore a step error i.e. do not exit if a container terminates with a non-zero exit code when onError is set to "continue"
201
206
if e .OnError != entrypoint .ContinueOnError {
202
207
os .Exit (status .ExitStatus ())
@@ -207,7 +212,7 @@ func main() {
207
212
log .Fatalf ("Error executing command (ExitError): %v" , err )
208
213
}
209
214
default :
210
- e . CheckForBreakpointOnFailure ( )
215
+ checkForBreakpointOnFailure ( e , breakpointExitPostFile )
211
216
log .Fatalf ("Error executing command: %v" , err )
212
217
}
213
218
}
0 commit comments