I am using circle CI 2.0 and have a manual approval step. Let’s call it job “A”.
I am trying to add a timeout for this job by running another job, “B” in parallel. In job B, I run a shell script with a certain timeout and then read an environment variable. Based on the value of the env variable, I either successfully end job B or throw an error.
In Job A, I set the value of the variable.
All jobs following, require both jobs, A and B, to be completed.
My question, hence, is: Is there a way in which I can share a variable between jobs A and B?
I wonder if it would be better to just have one approval job in the workflow, and then if that goes ahead, read meta-data (either using the API or the env vars) to see how long the job waited for approval. If it is too long, cause a job failure.
(I have not worked with approval jobs, but that is how I would tackle the problem if I wanted such a thing).
I agree with your solution.
However, in the condition that the job is never approved by anyone, the workflow remains in pending.
That is what I am more concerned about as we do not want pending workflows. Failed is fine.
I wonder if you could do this - have two parallel jobs (B, C) that come from a parent (A). Job B contains the approval and C contains a timer task.
At the end of the timer, C checks the status of B using the API, and if B was approved, C does nothing, and if B was not approved, C fails, causing the whole workflow to fail. I don’t know if this is possible, but it might be worth a try?
(This will lock up two build machines for the duration of the wait, but I don’t think there is any way around that. That said, I suppose you could have a scheduled task that run periodically to kill/fail any long-running waits, so you only lock up one server and not two).
I went with something similar.
I have a job A for manual approval, job B that depends on A, which writes to a file and caches it.
A job C that runs in parallel to both A and B that is a timer. and checks the contents for the file from cache.
Depending on the content, the job either succeeds or fails,
All other jobs depend on Job B and job C.
However, when job C fails due to incorrect file value, it leaves the workflow in “Failing” status. not failed.
Any idea to cancel/fail the workflow from a job?
Ah, because the approval step is still waiting for an answer?
Does the API offer a cancel/fail feature?
OK. So this is where you have an opportunity to work around a small gap in the “serverless” provision of hosted CI. I would suggest spinning up a small web app to handle approvals (to be deployed to your preferred cloud provider).
This can output a yes/no response in JSON that a timer task can detect. You’d need to use some sort of auth (e.g. htauth) to ensure only authorised persons can use it.
It’s not ideal, but in my experience all non-trivial usages of hosted CI will require some work-arounds. Also, add a feature request to the CircleCI Ideas portal .