Junior — Middle
What actions are available when using Job.build in GitLab CI?
sobes.tech AI
Answer from AI
In GitLab CI, the Job.build method is used to create a new instance of a job based on the configuration. When using Job.build, you can programmatically define job parameters such as name, scripts, artifacts, and other settings, but the job itself is not yet started.
Available actions when using Job.build include:
- Creating a new job with specified parameters.
- Setting environment variables for the job.
- Defining dependencies and launch conditions.
- Preparing the job for execution, but without starting it immediately.
Example of usage in Ruby (GitLab Runner):
job = Gitlab::Ci::Build::Job.build(name: 'test', script: ['echo Hello'])
job.variables = [{ key: 'VAR', value: 'value' }]
# The job is ready to run but has not been started automatically
Thus, Job.build allows programmatic creation and configuration of jobs in GitLab CI, but additional invocation or process is required to run them.