Create a .gitlab-ci.yml file in your repository that runs a basic job (e.g., running a script or test). Ensure the pipeline runs automatically on push

Create a .gitlab-ci.yml file in your repository that runs a basic job (e.g., running a script or test). Ensure the pipeline runs automatically on push

To create a .gitlab-ci.yml file in your GitLab repository that runs a basic job (like executing a script or running tests) and ensures the pipeline runs automatically on push, follow these steps:

Step 1: Create the .gitlab-ci.yml File

  1. In your project directory, create a new file named .gitlab-ci.yml:

     touch .gitlab-ci.yml
    
  2. Open the file in your text editor.

Step 2: Define a Basic CI/CD Job

Add the following content to the .gitlab-ci.yml file. This example runs a simple script that echoes "Hello, World!":

stages:          # Define stages
  - build       # This is a build stage

hello_world_job:  # Define a job
  stage: build    # Specify the stage for the job
  script:         # Commands to run
    - echo "Hello, World!"  # This command will run in the job

Step 3: Commit and Push the Changes

  1. Save the .gitlab-ci.yml file.

  2. Stage and commit the changes:

     git add .gitlab-ci.yml
     git commit -m "Add GitLab CI configuration file"
    
  3. Push the changes to your GitLab repository:

     git push origin main
    

    Replace main with your current branch if it's different.

Step 4: Verify the Pipeline

  1. Go to your GitLab project page.

  2. Navigate to the CI/CD > Pipelines section on the left sidebar.

  3. You should see a new pipeline that was triggered automatically upon the push.

Summary

You've created a .gitlab-ci.yml file that defines a basic job, and you've configured your GitLab repository to run the pipeline automatically on push. If you have any questions or need further assistance, feel free to ask!