Create a build pipeline and push Image to external repository with Azure Devops

Azure Devops is the powerful Microsoft product for Devops solutions. In this article I will explain how you can create a build pipeline using predefined actions and tools provided in order to push an image to an external repository like Docker hub.

As a first step you should create two new service connections. As I am using Github, the one will be a github connection and a docker hub connection. To accomplish that you should go to project settings -> service connections and connect your accounts with your password credentials.

When you complete this step, the connected accounts will appear.

Then you should go to pipelines menu and create a new one. My pipeline has the name main-pipeline.

Azure Devops provides a large list of predefined tasks that will make your implementation easier and quicker. In my case I selected the build of a Dockerfile that will be listed in the Github repository.

In more detail the code will be checkout from the repository and the image will be created using a building machine that Azure provides from a shared pool of agents.

You can find the pipeline code below:

# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- master

resources:
- repo: self

variables:
  tag: 'latest'

stages:
- stage: Build
  displayName: Build image
  jobs:
  - job: pushToDocker
    displayName: pushToDocker
    steps:
    - task: Docker@2
      displayName: Build an image
      inputs:
        containerRegistry: 'geralexgr-docker-repo'
        repository: 'geralexgr/aksjavarepo'
        command: 'buildAndPush'
        Dockerfile: '**/Dockerfile'
        tags: latest
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'

A successful run of the pipeline is shown below. As the code indicates the tag of the image should be the latest.

The created image will be stored on docker hub as indicated in the instructions.

You can then go and pull your image locally to test the result. In my case I would use:

docker pull geralexgr/aksjavarepo:latest

Create a self hosted agent on local machine for Azure Devops

Azure Devops services provide great functionality for deployment solutions. One of them is the local agent creation if you do not have a cloud/hosted available server.

In this article I will explain the procedure on how to create one.

Go to your project on your organisation and select agent pools. You can choose either the default or create a new one.

When selecting your agent pool, you should press on new agent. There you can find instructions on how to create your agent. In my case it is a Mac OS X machine

Download the files and follow the instructions. The configuration steps for Mac OS X ask for the server URL. You should input the below:

https://dev.azure.com/Your_Org_Name

Then you should select PAT authentication and generate a new token from your account panel -> personal access tokens.

Input the access permissions for the token and the expiration date. Also copy the key on a safe place. If you do not provide sufficient access on the token, you will get errors during the configuration.

When the configuration is completed agent will try a test connection.

When the above step is finished, try to run the agent.

./run.sh on macosx

If the procedure is succeful you will see your machine ready to accept jobs

Also the agent should appear online under agents tab

Bad HTTP response returned from server Code 500 – Ansible authentication

When you try to connect through kerberos with a domain account on Ansible windows hosts, you may encounter the error that is shown below:

The configuration for the kerberos connection. is listed below, and you can find the steps on my previous article.

[all:vars]

ansible_connection = winrm
ansible_winrm_server_cert_validation = ignore
ansible_port =  5985
ansible_user = domainUser
ansible_password = password
ansible_become_method= runas
ansible_winrm_transport = kerberos

The problem occur while trying to connect with port 5985 unencrypted on the remote machine. To bypass the problem you could run on PowerShell the below command which allows an unencrypted connection through winrm protocol.

Set-Item -Path WSMan:\localhost\Service\AllowUnencrypted -Value true

Lastly you could try a test connection to verify the result.

PHP Warning: Module “xxx” is already loaded in Unknown on line 0

After updating a php installation on a webserver I noticed the error that is listed below. This indicates that a module tried to be loaded, but it was running successfully. As a result you should have a duplicate entry of loading the module somewhere.

The error will be shown if you type for example php -v

PHP Warning:  Module "igbinary" is already loaded in Unknown on line 0

Try to locate which module has a duplicate entry. In my example it was igbinary.

php --ini | grep igbinary

Remove the duplicate load and the warning should be dismissed.