The thickness of amalgamations of graphs